Search code examples
c++lnk2019

LNK 2028 unresolved token & LNK 2019 unresolved extern symbol


I'm working with VS 2013, using UI forms. In MyForm.h there is a code

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

void b()
{
    A var;
}

I get those errors:

Error   2   error LNK2028: unresolved token (0A00000A) "public: __thiscall A::A(void)" (??0A@@$$FQAE@XZ) referenced in function "void __cdecl b(void)"
Error   3   error LNK2028: unresolved token (0A00000B) "public: __thiscall A::~A(void)" (??1A@@$$FQAE@XZ) referenced in function "void __cdecl b(void)"
Error   4   error LNK2019: unresolved external symbol "public: __thiscall A::A(void)" (??0A@@$$FQAE@XZ) referenced in function "void __cdecl b(void)"
Error   5   error LNK2019: unresolved external symbol "public: __thiscall A::~A(void)" (??1A@@$$FQAE@XZ) referenced in function "void __cdecl b(void)"

I've already googled for about two hours, but, still no result.


Solution

  • You have to define the constructor and destructor like:

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