You are misleading pointers and variables without pointers. new Player() returns the address of the dynamically allocated Player object. You cannot assign this address to a non-pointer Player variable; you need to declare Player as a pointer:
Player* player = new Player();
You also need to remember the freed memory with the corresponding delete :
// player starts out pointing to nothing Player* player = 0; //New game method Game::New() { // If player already points to something, release that memory if (player) delete player; player = new Player(); }
Now that Player is a pointer, you will need to update any other code that you wrote that uses the player to use the member -> access operator . For example, player.name() will become player->name()
source share