I have a class and want one of hte private members to be a string, but im having trouble initializeing it in the constructor function.
here is the class
here is the constructorCode:// Player class declaration class Player { private: char* playerName; short int hitpoints; short int strength; short int agility; short int magic; short int gold; public: Player(); // constructor // no destructor void reportStats(); // shows stats void attack(); // kill monster void move(); // move N, E, S, or W (do i need parameters?) void rest(); // sleep to regain health void setPlayerInfo(); // name, sex void showPlayerInfo(); // for debugging only };
is this how i am supposed to declare that data member and initialize it? i get weird errors and funny things when i try to display the data member.Code:Player::Player() // constructor definition { playerName = "Brian"; strength = 10; agility = 10; hitpoints = 10; magic = 20; gold = 20; }



LinkBack URL
About LinkBacks



..