Thread: What is Visual C++ saying?

  1. #1
    Registered User
    Join Date
    Sep 2008

    What is Visual C++ saying?

    Okay, so I am making a text RPG, and for some reason the Player object makes this error:
    player.obj : error LNK2001: unresolved external symbol "public: void __thiscall PLAYER::SetAmo(int)" (?SetAmo@PLAYER@@QAEXH@Z)
    C:\Documents and Settings\Glitch\Desktop\Games\Skets series\Skets in CRYSTAL BOND\Release\Skets in CRYSTAL BOND.exe : fatal error LNK1120: 1 unresolved externals
    I don't get it at all, does anyone know if they can help me, Player's code is:
    //Player behavior
    class PLAYER
    		int level;
    		int gems;	//Gems are money
    		int exp;
    			int atk;	//Attack
    			int def;	//Defence
    			int spd;	//Speed
    			int hlt;	//Health
    			int amo;	//Laser Energy
    			int MaxHlt;		//Maxium Health
    			int MaxAmo;		//Maxium Laser Energy
    		void SetName(char* newname);
    		void GetName();
    			void SetGems(int newgems);
    			void AddGems(int value);
    			int GetGems();
    		//Current Health and Laser Energy
    			void SetHlt(int newhlt);	//Health
    			void AddHlt(int value);
    			int GetHlt();
    			void SetAmo(int newAmo);		//Laser Energy
    			void AddAmo(int value);
    			int GetAmo();
    			void SetAtk(int newatk);	//Attack
    			int GetAtk();
    			void SetDef(int newdef);	//Defence
    			int GetDef();
    			void SetSpd(int newspd);	//Speed
    			int GetSpd();
    			void SetExp(int newexp);	//Experience
    			void AddExp(int addexp);
    			int GetExp();
    			void SetMaxHlt(int newMaxHlt);	//Max Health
    			int GetMaxHlt();
    			void SetMaxAmo(int newMaxAmo);	//Max Laser Energy
    			int GetMaxAmo();
    Thanks in advanced, no need to break the code down, I mainly want to know what error Visual C++ is giving me.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Farncombe, Surrey, England
    You have, probably, not defined the function SetAmo for that class.

    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Banal internet user
    Join Date
    Aug 2002
    It means that SetAmmo isn't defined anywhere that the linker knows to look.

  4. #4
    Join Date
    Oct 2007
    Inside my computer
    player.obj : error LNK2001: The public class member function SetAmo that takes an int that is located in the class PLAYER was not found. Please implement it.
    C:\Documents and Settings\Glitch\Desktop\Games\Skets series\Skets in CRYSTAL BOND\Release\Skets in CRYSTAL BOND.exe : fatal error LNK1120: 1 function could not be found.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    It means you declared SetAmo(int) but failed to define it.

  6. #6
    The larch
    Join Date
    May 2006
    One mistake I make quite often that can result is that when the function is defined I forget to mark it as a member function.

    //void SetAmo(int newAmo) {...}
    void PLAYER::SetAmo(int newAmo) {...}
    As to the general design of the class, well that's how tutorials often teach it. Hide members and provide accessors for everything.

    However, it also shows that this class is supposed to be entirely controlled from the outside and the only purpose it serves is hiding the data, hence making external controlling more awkward.

    I don't mean that you should make the members public, but might instead consider moving some of the functionality into the class. What you should see as a result are method names that describe actual actions (attack, defend, level_up, buy_ammo etc) rather than name manipulations of particular member variables. (Getters are somewhat more acceptable - you may want to query the class for info -, but abundance of setters indicates that the class might not be doing much useful.)
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  2. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  3. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 10:43 AM
  4. Errors with including winsock 2 lib
    By gamingdl'er in forum C++ Programming
    Replies: 3
    Last Post: 12-05-2005, 08:13 PM
  5. Learning OpenGL
    By HQSneaker in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2004, 08:57 AM

Tags for this Thread