How to initialize object within another class

Here is a code:
WEAPON:

class WeaponType { };

class Swords : public WeaponType { };

PLAYER:

class Player {

public:
WeaponType *weapon;

void setWeapon() {
this->weapon = new Swords(); // get error on this line
}


Error 1 error LNK2019: unresolved external symbol "public: __thiscall Swords::Swords(void)" (??0Swords@@QAE@XZ) referenced in function "public: __thiscall Footman::Footman(int)" (??0Footman@@QAE@H@Z)

Error 2 error LNK1120: 1 unresolved externals D:\PROJECTS\C++\AdventureGame\Debug\AdventureGame.exe AdventureGame


Any suggestions how to solve ? Im writing an adventure text-based game, so that the player needs to be able to swith between weapons.

Sorry for my bad english :P
It looks like class Plyer does not see the definition of class Swords. You should show how the code is distributed among files.

If you need more details with your code and how to set an appropriate weapon in your class Plyer you can ask me at www.clipper.borda.ru

Last edited on
Topic archived. No new replies allowed.