在Visual Studio中编码时,我得到了一个未解决的外部符号错误 我不知道该怎么办我不知道怎么了。 你能帮我破译一下吗?我应该在哪里寻找什么样的错误?

1>Form.obj : error LNK2019: unresolved external symbol "public: class Field * __thiscall Field::addField(class Field *)" (?addField@Field@@QAEPAV1@PAV1@@Z) referenced in function "public: void __thiscall Form::parse(class std::basic_stringstream<char,struct std::char_traits<char>,class std::allocator<char> > &)" (?parse@Form@@QAEXAAV?$basic_stringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
1>Form.obj : error LNK2019: unresolved external symbol "public: virtual void __thiscall Field::parse(class std::basic_stringstream<char,struct std::char_traits<char>,class std::allocator<char> > &)" (?parse@Field@@UAEXAAV?$basic_stringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "public: __thiscall InputField::InputField(class std::basic_stringstream<char,struct std::char_traits<char>,class std::allocator<char> > &)" (??0InputField@@QAE@AAV?$basic_stringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
1>Form.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall Field::prompt(void)" (?prompt@Field@@UAEXXZ)
1>Form.obj : error LNK2001: unresolved external symbol "public: virtual class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall Field::getName(void)" (?getName@Field@@UAE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ)
1>Form.obj : error LNK2001: unresolved external symbol "public: virtual class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall Field::getType(void)" (?getType@Field@@UAE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ)
1>Form.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall Field::describe(void)" (?describe@Field@@UAEXXZ)
1>C:\Users\tomy\Documents\Visual Studio 2010\Projects\zapoctovkac++\Debug\zapoctovkac++.exe : fatal error LNK1120: 6 unresolved externals

当前回答

导致此链接器错误的一个可能原因还可能是在头文件中声明但没有定义的内联函数,该头文件随后包含在其他地方。内联函数必须在使用它们的每个翻译单元中定义。

其他回答

只是花了几个小时才发现问题是我的主文件扩展名是。c而不是。cpp

:/

我只是一时难以接受。一切都是有逻辑的。我声明了一个构造函数,但没有定义它

class SomeClass
{
   SomeClass();  // needs the SomeClass::SomeClass(){} function defined somewhere, even here
}

当我忘记这么基本的东西时,我的头差点撞到键盘上。

确保您没有试图将插入或提取操作符作为内联函数重载。我有这个问题,它只消失了,当我删除了那个关键字。

此错误通常意味着某些函数有声明,但没有定义。

例子:

// A.hpp
class A
{
public:
  void myFunc(); // Function declaration
};

// A.cpp

// Function definition
void A::myFunc()
{
  // do stuff
}

在你的情况下,找不到定义。问题可能是你包含了一个头文件,它带来了一些函数声明,但是你要么:

不要在CPP文件中定义函数(如果这段代码是您自己编写的) 不包括包含定义的lib/dll文件

一个常见的错误是你将一个函数定义为一个独立的函数,而忘记了类选择器,例如在你的.cpp文件中A::::

错误:void myFunc() {/* do stuff */} 右:void A::myFunc() {/* do stuff */}

我的问题是一个sconscript没有定义在它的cpp文件。这可能非常令人困惑,因为Visual Studio在项目中有cpp文件,但正在构建的完全是其他东西。