April 2017
Beginner to intermediate
394 pages
9h 16m
English
The next idea is aggregation, which is designated by the HAS-A relationship. This is when a single class contains a collection of instances of other classes that are obtained from somewhere else in your program. These are considered to have a weak HAS-A relationship as they can exist outside of the confines of the class.
In this case, I created a new class called CombatEncounter which can have an unlimited number of enemies that can be added to it. However when using aggregation, those enemies will exist before the CombatEncounter starts; and when it finishes, they will also still exist. Through code it would look something like this:
class CombatEncounter { public: void AddEnemy(Enemy* pEnemy); private: std::list<Enemy*> ...Read now
Unlock full access