未解析的外部符号,尝试修复时遇到问题
unresolved external symbol, having trouble trying to fix
您好,我从下面的代码中收到此错误:
Error 4 error LNK2019: unresolved external symbol "public: __thiscall Noun::Noun(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??0Noun@@QAE@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@0@Z) referenced in function "public: __thiscall Dictionary::Dictionary(void)" (??0Dictionary@@QAE@XZ)
我想这个错误来自没有声明构造函数Noun(string word, string definition);
我也不确定如何声明它以消除错误,以便我可以编译我的代码。下面是我的代码。
链接器抱怨您没有为 Noun
的构造函数添加定义。添加它,此错误将被修复。我相信你的意思只是在其中调用父级的构造函数,所以也许这会完成这项工作:
Noun(string word, string definition) : Word(word, definition) {}
您可以定义构造函数
Noun(string word, string definition)
与您使用类Word
的构造函数所做的完全相同。但是你需要确保在使用它时知道名词的定义。通常,为此使用单独的头文件。类 Noun
的头文件的内容已经包含在您给出的代码中: 它以
class Noun : public virtual Word {
并以
};
将其移动到名为 noun.h 的头文件中,并通过以下方式将其包含在您的 cpp 文件中
#include "noun.h"
- 编译包含字符串的代码时遇到问题
- 如何在C++向量中奇数元素前面加上值-1,我在使用insert函数时遇到了问题
- 在 for 循环中查找问题时遇到困难
- 代码在我的计算机上运行良好,但是在将其提交给coursera时遇到未知的信号11问题
- 在顶点着色器中使用 OpenGl 的未声明标识符,我在顶点着色器中绘制三角形时遇到问题
- 从其他类访问类时遇到问题
- 打印问题.我在数组中打印值时遇到一些问题
- 使用静态成员声明类时遇到问题
- C++ 填充数组时遇到问题
- 遇到此问题时遇到困难:允许用户输入数组的值并使用 for,而循环也输出输入的最大数字
- 我在使用C++文件时遇到了一些问题
- 在将字符串放入字符串向量时遇到问题?
- 余数除法和不允许除以零 (c++) 时遇到问题
- 我在C++中使用 getline() 函数时遇到问题
- C++线程安全:如果只有一个线程可以写入非原子变量,但多个线程从中读取. 会遇到问题吗?
- 在我的四叉树实现中遇到问题
- 在 c++ 中循环遍历数组时遇到问题
- 我遇到了黑客排名中的问题"TWO STRINGS"的三个测试用例的分段错误。原因是什么?
- 使用 MinGW 在 Windows 上构建 GLEW 时遇到问题
- 编译 Cilk Plus 程序时遇到问题