Hi I am making a pretty large text game and I now have to make the player file.
I am torn betwen either this:
which looks like I am attempting to find a way round of not global variablesCode:struct Player { static string m_nm; static int m_hp; }; string m_nm = ""; int m_hp = 100;
or this way: ps - this a basic example of what I might do
Basicly, I was thinking of doing the second method, all the Player data membersCode:class Player { public: Player(); ~Player(); protected: // pointers string *m_nm; int *m_hp; }; Player::Player() { m_nm = new string(""); m_hp = new int(100); } Player::~Player() { delete m_nm; m_nm = NULL; delete m_hp; m_hp = NULL; } int main() { Player *play = new Player; delete play; play = NULL; return 0; }
woulds be derived from a base class.
Which method is best to use?



LinkBack URL
About LinkBacks



Think of the difference between both and use that as the basis for your decision. If you want to build an object class that is mainly composed of public access members (functions and data), use a struct. Otherwise use a class. You can still do the other way around, nothing stopping you. The compiler will not care as long as the access labels are correctly placed. But... you and all other humans reading your code will more readily understand it.