Its meant for implementing something like this
1 2 3 4 5 6 7 8
|
Game_object* Game_object::Get_pointer_by_string(std::string input_string)
{ for(std::vector<Game_object*>::iterator it = Game_objects_list.begin(); it != Game_objects_list.end(); ++it)
{ if((*it)->name == input_string)
{ return (*it);
}
}
}
| |
Obviously a brutal example, since it doesnt return anything if the string doesnt match...
So this would be handy if I wanted to go to some game object & set a target object for it to follow/attack/etc.
But I cant do that once I make these lists members of the game_engine class I mentioned earlier.
I have no idea why the build process on linux didnt cough up a hairball. I suspect it was because I simply compiled the main cpp file with g++, & #included all of the cpps into there, so that they were all compiled into the same object.
Im sorry, but you completely lost me with that example. What the heck is extern?
I follow what you mean about declaring global objects in headers defined in a single source, but I cant in this instance, since both the game objects & game engine cpp need to see the definitions for the game object types. I think Im stuck with it like this.