Re: OT: Stupid c++
Multiple cpp files means externs if you use globals to share info between them.
But for an object-oriented design, you have a class definition file (Foo.h) and a class implementation file (Foo.cpp) for each class, and then you use them in the context of other classes. This way, almost all the code you write solves problems for general cases, and the specific application implementation (e.g. the actual Main function of an application) can then be something more general, simple and high-level.
So Character defines a character object in so general a way, that its .h and .cpp files don't need to refer to the instance of them at all - they refer only to the definition of other related classes, but never to a specific object (or else they'd be usable only with that specific object).
So your list of classes might be something like:
GameState
Level
Character
Item
Potion
Weapon
Armor
Each would have two files, a .h and a .cpp. All would be generic implementations.
Then you'd have a Main.cpp file where the entry point and specific objects are declared. In it you'd have maybe just one GameState object, and just a few calls to its methods, like:
GameState.CreateNewGame();
GameState.Load( SavedGame );
GameState.Play();
GameState itself might have a protected Initialize() method which would be called by both CreateNewGame() and Load(), and GameState would have the only Vectors storing all the objects representing stuff that exists in the game universe.
Etc.
PvK
|