I know this is probably a basic question, but does anybody know how to call a member function of a class instance from inside a scope in which the instance is not defined?
For example, I have a Game class and a Player class. I want a member function inside of the Game class to access a member function of an instance (for example, Nate) of the Player class and get the return value. In other words, I want the instance Player::Nate to call a function in the gameLoop() function that is part of Game::game.
ID:1663332
Aug 21 2014, 6:05 pm
|
|
Aug 22 2014, 3:16 am (Edited on Aug 22 2014, 4:08 am)
|
|
Pass a pointer or reference to Game::game to the instance Player::Nate and call it like this: (partially assumes C++11)
|
In response to Pokemonred200
|
|
Kids these days and their damn shared_ptr's. I remember when all we had was a stupid star and we had to delete everything manually.
|
In response to ExPixel
|
|
ExPixel wrote:
Kids these days and their damn shared_ptr's. I remember when all we had was a stupid star and we had to delete everything manually. So do I, actually. It's how I was first taught. But these shared_ptrs make life easier :D |