- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
-6ren">
我的任务是编写代码以使用递归跟踪排序的链表。我们得到了类和文件的组成,但需要填写函数。我收到四个错误,我认为它们是由在公共(public)函数中调用私有(private)函数引起的。我的错误是:
1>SortedList.obj : error LNK2019: unresolved external symbol "public: void __thiscall SortedList::recursiveMakeEmpty(class NodeType * &)" (?recursiveMakeEmpty@SortedList@@QAEXAAPAVNodeType@@@Z) referenced in function "public: void __thiscall SortedList::makeEmpty(void)" (?makeEmpty@SortedList@@QAEXXZ)
1>SortedList.obj : error LNK2019: unresolved external symbol "public: bool __thiscall SortedList::recursiveInsert(class NodeType * &,int)" (?recursiveInsert@SortedList@@QAE_NAAPAVNodeType@@H@Z) referenced in function "public: bool __thiscall SortedList::insert(int)" (?insert@SortedList@@QAE_NH@Z)
1>SortedList.obj : error LNK2019: unresolved external symbol "public: bool __thiscall SortedList::recursiveDelete(class NodeType * &,int)" (?recursiveDelete@SortedList@@QAE_NAAPAVNodeType@@H@Z) referenced in function "public: bool __thiscall SortedList::deleteItem(int)" (?deleteItem@SortedList@@QAE_NH@Z)
1>SortedList.obj : error LNK2019: unresolved external symbol "public: void __thiscall SortedList::recursivePrint(class NodeType * &)" (?recursivePrint@SortedList@@QAEXAAPAVNodeType@@@Z) referenced in function "public: void __thiscall SortedList::printList(void)" (?printList@SortedList@@QAEXXZ)
1>C:\Users\Ross\documents\visual studio 2010\Projects\Recursive Sorted List\Debug\Recursive Sorted List.exe : fatal error LNK1120: 4 unresolved externals
我的代码:
节点.h
typedef int ItemType;
class NodeType
{
public:
ItemType info;
NodeType *next;
};
排序列表.h
#include "MyClass.h"
string MyClass::foo = "bar" #pragma once
#include <iostream>
#include "Node.h"
using namespace std;
class SortedList
{
public:
SortedList();
// Constructor used before any operations are done on the list. Initializes the list to empty.
// Preconditions: None.
// Postconditions: List is an empty list.
~SortedList();
// Destructor used when a List is no longer in scope.
// Precondition: None.
// Postcondition: No dynamic variables exist.
void makeEmpty();
// Makes the list empty if it is not empty already.
// Preconditions: The list may be empty or have items in it.
// Postconditions: List is now an empty list. Any dynamically allocated memory which is no longer used is returned to the system.
The current position is 1.
// Note: This function body is different from the constructor.
bool isEmpty();
// Returns True if List is an empty list; return False otherwise.
// Postconditions: List remains unchanged.
bool isFull();
// Returns True if List is full; returns False other wise.
// Postcondition: List remains unchanged.
// Note: For linked list implementation, you can simply return false.
bool insert( ItemType newItem );
// Inserts the given newItem in the list maintaining sorted order.
// Preconditions: The list may be empty.
// Postconditions: If the list already contained a matching item, the function returned false and the list is unchanged.
// Otherwise the newItem is inserted in the linked list so that the list maintains sorted order, and true is returned.
bool deleteItem( ItemType deleteItem );
// Deletes the item from the linked list if it is found.
// Preconditions: List may be empty. At most one matching item is in the list.
// Postconditions: If the itemwas in the list, it is deleted and true is returned. If the item was not in the list, the list is
unchanged and false is returned.
void printList();
// Prints items in the list
// Preconditions: Assumes that the operator << has been defined for ItemType.
// Postcondition: Items on the list have been printed to the standard output. List is unchanged.
private:
NodeType *head;
// Points to head of linked list.
void recursiveMakeEmpty( NodeType *& node);
// Makes the list empty if it is not empty already.
// Preconditions: The list may be empty or have items in it.
// Postconditions: List is now an empty list. Any dynamically allocated memory which is no longer used is returned to the system.
The current position is 1.
bool recursiveInsert( NodeType *& node, ItemType newItem );
// Inserts the given newItem in the list maintaining sorted order.
// Preconditions: The list may be empty.
// Postconditions: If the list already contained a matching item, the function returned false and the list is unchanged.
// Otherwise the newItem is inserted in the linked list so that the list maintains sorted order, and true is returned.
bool recursiveDelete( NodeType *& node, ItemType deleteItem );
// Deletes the item from the linked list if it is found.
// Preconditions: List may be empty. At most one matching item is in the list.
// Postconditions: If the itemwas in the list, it is deleted and true is returned. If the item was not in the list, the list is
unchanged and false is returned.
void recursivePrint( NodeType *& node );
// Prints items in the list
// Preconditions: Assumes that the operator << has been defined for ItemType.
// Postcondition: Items on the list have been printed to the standard output. List is unchanged.
};
排序列表.cpp
#include "SortedList.h"
SortedList::SortedList()
// Constructor used before any operations are done on the list. Initializes the list to empty.
// Preconditions: None.
// Postconditions: List is an empty list.
{
head = NULL;
}
SortedList::~SortedList()
// Destructor used when a List is no longer in scope.
// Precondition: None.
// Postcondition: No dynamic variables exist.
{
makeEmpty();
}
void SortedList::makeEmpty()
// Makes the list empty if it is not empty already.
// Preconditions: The list may be empty or have items in it.
// Postconditions: List is now an empty list. Any dynamically allocated memory which is no longer used is returned to the system. The current position is 1.
// Note: This function body is different from the constructor.
{
recursiveMakeEmpty(head);
}
bool SortedList::isEmpty()
// Returns True if List is an empty list; return False otherwise.
// Postconditions: List remains unchanged.
{
return ( head == NULL );
}
//
bool SortedList::isFull()
// Returns True if List is full; returns False other wise.
// Postcondition: List remains unchanged.
// Note: For linked list implementation, you can simply return false.
{
return false;
}
bool SortedList::insert( ItemType newItem )
// Inserts the given newItem in the list maintaining sorted order.
// Preconditions: The list may be empty.
// Postconditions: If the list already contained a matching item, the function returned false and the list is unchanged.
// Otherwise the newItem is inserted in the linked list so that the list maintains sorted order, and true is returned.
{
return recursiveInsert( head, newItem );
}
bool SortedList::deleteItem( ItemType deleteItem )
// Deletes the item from the linked list if it is found.
// Preconditions: List may be empty. At most one matching item is in the list.
// Postconditions: If the itemwas in the list, it is deleted and true is returned. If the item was not in the list, the list is unchanged and false is returned.
{
return recursiveDelete( head, deleteItem );
}
void SortedList::printList()
// Prints items in the list
// Preconditions: Assumes that the operator << has been defined for ItemType.
// Postcondition: Items on the list have been printed to the standard output. List is unchanged.
{
recursivePrint( head );
}
bool recursiveInsert( NodeType *& node, ItemType newItem )
// Inserts the given newItem in the list maintaining sorted order.
// Preconditions: The list may be empty.
// Postconditions: If the list already contained a matching item, the function returned false and the list is unchanged.
// Otherwise the newItem is inserted in the linked list so that the list maintains sorted order, and true is returned.
{
if( node == NULL )
{
node = new NodeType;
node->info = newItem;
node->next = NULL;
return true;
}
else if( node->info == newItem )
{
return false;
}
else if( newItem < node->next->info )
{
NodeType* ptr = new NodeType;
ptr->info = newItem;
ptr->next = node->next;
node->next = ptr;
return true;
}
else
{
recursiveInsert( node->next, newItem );
}
}
bool recursiveDelete( NodeType *& node, ItemType deleteItem )
// Deletes the item from the linked list if it is found.
// Preconditions: List may be empty. At most one matching item is in the list.
// Postconditions: If the itemwas in the list, it is deleted and true is returned. If the item was not in the list, the list is unchanged and false is returned.
{
if( node == NULL )
{
return false;
}
else if( node->next->info == deleteItem )
{
NodeType* ptr = node->next->next;
delete node->next;
node->next = ptr;
return true;
}
else
{
recursiveDelete( node->next, deleteItem );
}
}
void recursiveMakeEmpty( NodeType *& node)
// Makes the list empty if it is not empty already.
// Preconditions: The list may be empty or have items in it.
// Postconditions: List is now an empty list. Any dynamically allocated memory which is no longer used is returned to the system. The current position is 1.
{
if( node == NULL )
{
return;
}
else
{
recursiveDelete( node, node->info );
}
}
void recursivePrint( NodeType *& node )
// Prints items in the list
// Preconditions: Assumes that the operator << has been defined for ItemType.
// Postcondition: Items on the list have been printed to the standard output. List is unchanged.
{
if( node == NULL )
{
return;
}
else if( node->next == NULL )
{
cout << node->info << "\n\n";
}
else
{
cout << node->info << ", ";
recursivePrint(node->next);
}
}
主要.cpp
#include "SortedList.h"
void menuSelection(char &selection);
int main()
{
char selection = 'S';
SortedList List;
ItemType item;
do
{
menuSelection(selection);
switch( selection )
{
case 'A':
cout << "What item would you like to add? ";
cin >> item;
if (List.insert(item))
{
cout << "\n Item has been added! \n\n";
}
else
{
cout << "\n Item already in list! \n\n";
}
break;
case 'D':
cout << "What item would you like to delete? ";
cin >> item;
if (List.deleteItem(item))
{
cout << "\n Item has been deleted! \n\n";
}
else
{
cout << "\n Item was not found! \n\n";
}
break;
case 'M':
List.makeEmpty();
cout << "\n List is now empty! \n\n";
break;
case 'P':
cout << "\n The list is: ";
List.printList();
cout << "\n\n";
break;
}
} while( selection != 'Q' );
return 0;
}
void menuSelection(char &selection)
{
cout << "What would you like to do? \n\n";
cout << "A - add item. \n";
cout << "D - delete item. \n";
cout << "M - make empty. \n";
cout << "P - print list. \n";
cout << "Q - quit. \n\n";
do
{
cin >> selection;
if( selection != 'A' && selection != 'D' && selection != 'M' && selection != 'P' && selection != 'Q' )
{
cout << "Must enter A, D, M, P, or Q.";
}
} while( selection != 'A' && selection != 'D' && selection != 'M' && selection != 'P' && selection != 'Q' );
}
最佳答案
您必须在所有方法定义之前添加 SortedList::
,甚至是 private
方法。
关于c++ - 错误 LNK2019 : unresolved external symbol "public: void __thiscall,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13275057/
几天前我问了一个类似的问题,它帮助我找到了 __declspec() 的正确方向,但我又被卡住了。我会尽可能清楚。希望有人能告诉我我做错了什么。它可能是一些小而简单的东西。 项目信息: jc:
我想在某些特定路径中创建某些文件的快捷方式(.lnk)。例如在 ("H:\happy\hi\new.lnk") 中创建我的文件 ("D:\New folder\new.exe") 的快捷方式我想用 p
This question already has answers here: What is an undefined reference/unresolved external symbol er
这个问题在这里已经有了答案: What is an undefined reference/unresolved external symbol error and how do I fix it?
我的 disk-on-key 中有一个可执行文件,位于 dir\program\prog.exe我想在 DoK 的根目录上有一个可执行文件的快捷方式,即 prog.lnk 将引用 dir\progra
我一直在寻找一种在 C# 中创建文件快捷方式的简单方法,但我只找到了执行此操作的外部 dll。这实际上非常令人惊讶,没有内置的方法可以做到这一点.. 无论如何,我知道 lnk 文件只是具有特定命令和给
我一直在寻找问题的解决方案,遇到了 JasonMArcher 回答的帖子,想知道我是否可以更具体地满足我的需求。 我们最近更换了一个新服务器,由于它的名称从//sbcmaster 更改为//sbcse
我有一堆.lnk文件,需要根据快捷方式指向的目标来区别对待它们。我发现很少有其他语言如何做到这一点,但与使用powershell做到这一点无关。 我已经试过了: $sh = New-Object -C
我在使用C++创建快捷方式时遇到问题。.lnk文件已创建,但是目标具有无效路径。 您能解释一下为什么这段代码没有创建正确的快捷方式吗?有人可以帮我修复我的代码吗? 这是代码 // RepChrome.
rmap_utils.h #ifndef UTILS_RANGE_MAP_H #define UTILS_RANGE_MAP_H #include #include #include #incl
这个问题在这里已经有了答案: Can't set value of static object field (error LNK2001: unresolved external symbol) (
我刚刚使用 NuGET 包管理器安装了 SFML 包。安装后。我从它的官方页面运行了一个基本程序。只需复制和粘贴。 #include int main() { sf::RenderWindo
这个问题在这里已经有了答案: Can't set value of static object field (error LNK2001: unresolved external symbol) (
这个问题已经有答案了: Windows shortcut (.lnk) parser in Java? (9 个回答) 已关闭 6 年前。 我在Windows的“最近的项目”中有一些文件夹/文件。我想
首先,对不起我的英语..如何将现有的快捷方式包含到我的解决方案中? 当我尝试将现有项目添加到我的项目中时,visual studio 似乎尝试添加链接目标,而不是链接本身,因为它给我以下错误: 找不到
我们有一个充满指向文件夹的快捷方式(.lnk 文件)的网络驱动器,我需要在 C# Winforms 应用程序中以编程方式遍历它们。 我有哪些实用选择? 最佳答案 添加 IWshRuntimeLibra
我正在编写 32 位服务应用程序,我希望能够在其中为登录用户 启动“开始”菜单项。我确实设法通过模拟用户并使用 CreateProcessAsUser 和命令行启动选定的 .lnk 文件来完成此任务:
当您尝试打开不再有效的快捷方式文件 (.lnk) 时,Windows 会提示您:“此快捷方式已被更改或移动,因此此快捷方式将不再正常工作。”是否有 python 代码可用于检测此类快捷方式是否不再有效
我有一个名为 Siemens NX 的程序的多个版本。 NX 使用环境变量进行配置。我需要 NX 10.0 使用一组与使用系统环境变量的 NX 7.5 不同的环境变量。因此,我编写了一个批处理文件来设
我有一个打开 *.postfix 文件的 c# 程序。 如果用户运行指向我的文件类型的 (.lnk) 快捷方式,我的程序将打开目标。 那么,我的程序怎么知道它是由 (.lnk) 快捷方式启动的(并获取
我是一名优秀的程序员,十分优秀!