My first large project with classes

New errors...

1
2
3
4
5
1
1>  Monster.cpp
1>main.obj : error LNK2019: unresolved external symbol "public: bool __thiscall Player::attack(class Monster &)" (?attack@Player@@QAE_NAAVMonster@@@Z) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "public: void __thiscall Player::displayHitPoints(void)" (?displayHitPoints@Player@@QAEXXZ) referenced in function _main
1>C:\Users\david\Documents\Visual Studio 2010\Projects\TextBasedRPG\Debug\TextBasedRPG.exe : fatal error LNK1120: 2 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Last edited on
Well, I suppose you forgot to #include "Player.h" in your monster.cpp. Or whatever header where Player is defined.
Line 2 is easy, in monster.cpp you are using a function that returns a type of time_t (type long) and storing it into an int, so you are potentially using bits. To get rid of this warning, where you call the function, store the value into a long instead of an int. You should not ignore this warning, because I'm guessing you are using it as a delay to control the speed of things, and when the unsigned int overflows you will most likely get a very hard to find error. (The error most likely being a complete and permanent freeze of your game, impossible to say without seeing how you are using it tho) (Also, this error will most likely only occur once every couple of years, so it might be a tad hard to spot in testing, lol)

line 4: You are using a type Player in monster.h, but never included whatever file contains the Player class. Easy fix, include the header for whatever file holds class Player in monster.h

line 6: You are using .getArmor, it needs to look like variable.getArmor, with variable being replaced by what you are trying to get the armor of. Perhaps you missed a space, or maybe it should be variable.getArmor(). If you can't solve this, post the function you are calling it in, and whatever class that contains the value getArmor.

line7: You never declared a totaldamage value. Should damage be capatilized?

line 8: Same as line 4, fixing line 4 should fix this too

line 10: Same as line 6, again, if you can't fix this, post the function you are calling this in, and whatever class contains the value takeDamage.

Edit: You said copying, where did you get the source code? If it's online, mind posting the link?
Last edited on
Yeah i fixed all those problems now im getting linker errors. :/

1
2
3
4
5
1
1>  Monster.cpp
1>main.obj : error LNK2019: unresolved external symbol "public: bool __thiscall Player::attack(class Monster &)" (?attack@Player@@QAE_NAAVMonster@@@Z) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "public: void __thiscall Player::displayHitPoints(void)" (?displayHitPoints@Player@@QAEXXZ) referenced in function _main
1>C:\Users\david\Documents\Visual Studio 2010\Projects\TextBasedRPG\Debug\TextBasedRPG.exe : fatal error LNK1120: 2 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
This means that you either didn't implement these two methods of Player at all, or didn't add the cpp file where they are defined to the project.
Topic archived. No new replies allowed.