【问题标题】:LNK 2028 unresolved token & LNK 2019 unresolved extern symbolLNK2028 未解析的令牌和 LNK2019 未解析的外部符号
【发布时间】:2015-03-02 06:49:34
【问题描述】:

我正在使用 VS 2013,使用 UI 表单。 在 MyForm.h 中有一段代码

class A
{
public:
    A();
    ~A();
private:
};

void b()
{
    A var;
}

我收到这些错误:

错误 2 错误 LNK2028:函数“void __cdecl b(void)”中引用的未解析令牌 (0A00000A)“public: __thiscall A::A(void)”(??0A@@$$FQAE@XZ) 错误 3 error LNK2028: unresolved token (0A00000B) "public: __thiscall A::~A(void)" (??1A@@$$FQAE@XZ) 在函数 "void __cdecl b(void)" 中引用 错误 4 错误 LNK2019:函数“void __cdecl b(void)”中引用的未解析外部符号“public: __thiscall A::A(void)”(??0A@@$$FQAE@XZ) 错误 5 错误 LNK2019:函数“void __cdecl b(void)”中引用的未解析外部符号“public: __thiscall A::~A(void)”(??1A@@$$FQAE@XZ)

我已经用谷歌搜索了大约两个小时,但仍然没有结果。

【问题讨论】:

  • 你既没有定义构造函数也没有定义析构函数。如果您想要默认定义,请在两个声明之后(分号之前)写 = default
  • 谢谢。把自己弄傻了。

标签: c++ lnk2019


【解决方案1】:

你必须像这样定义构造函数和析构函数:

class A{
public:
    A();
    ~A();
private:
};
  A::A(){
}
  A::~A(){
}
void b()
{
  A var;
}

【讨论】:

  • 谢谢,但哥伦布已经在 cmets 中解决了这个问题。你知道吗,顺便说一句,如果“Type”是模板 ,我可以使用“pair ”吗?编译器说错误 C2079: 'std::pair::first' 使用未定义的类 'Type'
  • 如果你在类之外定义每个函数,你必须在定义每个函数之前写:模板
  • 我的意思是我有一个 template <class Type> class List { private: list < pair < Type, int > > _list; int amount, max_amount, type; public: 它说 'std::pair::first' 使用未定义的类 'Type'
  • 我不知道。你能以某种方式把完整的代码发给我吗?
  • 我不确定。如果我们将它定义为模板类型(如模板 ),我只是不明白 can pair 接受一个参数。它不起作用。说:'std::pair::first' 使用未定义的类 'Type'
猜你喜欢
  • 2014-11-07
  • 2013-06-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-06
  • 2014-09-19
  • 2012-12-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多