Hmm i hate these linking errors, the error messages are next to useless. Or at least seem it. Here's whats up, all im doing is making up some classes to show use of inheritance. It compiles ok, then I get this error at link time:
CCharacter.obj : error LNK2001: unresolved external symbol "public: __thiscall CPlayer::CPlayer(void)" (??0CPlayer@@QAE@XZ)
Debug/CCharacter.exe : fatal error LNK1120: 1 unresolved externals

the relevant code is:

Code:

class CPlayer : public CCharacter
{
public:

CPlayer();

void Move() {cout << m_sName << " moves" << endl;}

};

int main()
{
CPlayer play1;

play1.Attack();
play1.Use();
play1.Move();

return 0;
}

01-09-2003

Polymorphic OOP

because you declared a default constructor and created an object, but never defined the constructor.

01-09-2003

Travis Dane

Those errors esually involve when the compiler found a
declareation of a function but not its definition, in other words
it cant find the function itself.
In this case, i can find the constructor, add this:

Code:

CPlayer::CPlayer()
{
}

under the class

01-09-2003

Travis Dane

Quote:

Originally posted by Polymorphic OOP because you declared a default constructor and created an object, but never defined the constructor.

No fair!! i post a nice explanation and you get to be first

01-09-2003

gazsux

thankyou, i added that, but now i get the error:
CCharacter.cpp(55) : error C2512: 'CCharacter' : no appropriate default constructor available

I keep getting this error, why is it? It appears to go if I take everytihng out of the constructor.

01-09-2003

PJYelton

Post your code for CCharacter as well as line 55 where you are creating the object.

01-09-2003

alpha

my guess would be that it wants you to provide a CCharacter default constructor (no parameters).

so i could do a default constructor with nothing, then add a copy constructor thingy like CCharacter::CCharacter( /* with all my stuff in*/)?

01-09-2003

Polymorphic OOP

As soon as you make a constructor it get's rid of the "default default" constructor -- so you have to either make one with default arguments, one with no arguments, or always pass data when you create instances (which is not good because you can't do this with arrays of objects).

01-09-2003

gazsux

still aint working... you see i remember the days when i used to enjoy programming... when i used to program in C :P