Search code examples
c++classlnk2019

LNK2019 Using untemplated classes


I'm getting linker errors when using Classes that reference other classes in them.

1>main.obj : error LNK2019: unresolved external symbol "public: __thiscall MovePattern::~MovePattern(void)" (??1MovePattern@@QAE@XZ) referenced in function "public: __thiscall Enemy::Enemy(int,int,class MovePattern,char)" (??0Enemy@@QAE@HHVMovePattern@@D@Z)
1>main.obj : error LNK2019: unresolved external symbol "public: __thiscall MovePattern::MovePattern(void)" (??0MovePattern@@QAE@XZ) referenced in function "public: __thiscall Enemy::Enemy(int,int,class MovePattern,char)" (??0Enemy@@QAE@HHVMovePattern@@D@Z)

It's from referencing this class:

class MovePattern{
    public: 
        char next;

        MovePattern();
        MovePattern(const MovePattern &old){
            p = old.p;
            pi = 0;
            next = p[0];
            n = p[0];
        }

        MovePattern(char *pattern){
            p = pattern;
            pi = 0;
        next = p[0];
        n = p[0];
        }
        ~MovePattern();

In this class:

class Enemy{
    public:
    Enemy(int a, int b, MovePattern p,char c)
    x = b;
    y = a;

    MovePattern pattern (p);
    symbol = c;

They are currently within the same .cpp file, and MovePattern is above Enemy.

I'm not sure what is going on here

Visual C++ 2010 Express with a blank console project, and I haven't found anything similar to my problem yet, any help would would be appreciated.


Solution

  • You've not defined the default constructor and the destructor, as listed below:

    MovePattern();  //default constructor
    ~MovePattern(); //destructor
    

    You've to define them IF you declare them. Declaration must have definition. Or else you'll get linker error when using them, either implicitly or explicitly.