In fact, we are going to take advantage of a feature of boardgames in general, and monopoly in particular: The type and number of components doesn't change during a game.
On the other hand, components move around in the game a lot. Components will refer to other components:
For every type of component, we will therefore keep one reference list of all their instantiations. This list will be a derivative of the Index class. We will implement those lists starting next week.
The pointer class will contain a member of the Key class. This will be the only data element to be read and written.
The other data element contained in the pointer class is a pointer to an Index, in which we will search for an element that has the same Key as the one stored in the pointer class. This element is initialized by the constructor. If you wonder why we aren't reading this data element, think of what kind of information this data element contains. The information is already known at compile time. Whoever uses a variable of the pointer class will know to which index this pointer will be refering to. The only thing we don't know is to which element the pointer is refering to.
If you wonder why we aren't overloading operator->(), the answer is: "not yet". The pointer class will serve as basis from which we will derive classes pointing to specific lists. These classes will overload operator->() (and operator*() and operator[]()). You will then be able to use our smart pointers the same way as you are used to using C pointers.
Note that the Pointer class is derived from Listable, so that we can create lists of pointers and assign a usefull meaning to operator++() and operator--(), later in the project.
Also note that the static pointer is neither private nor public. It's protected. This means that only member functions of derivatives of Base may access this pointer. This effectively protects our game data from being tampered by non-member functions, while still allowing member functions to access this data. Note that this is much better technique than declaring a global variable
This pointer will be set by the Game constructor. Refer to the way Indexable initializes its base class. Add a constructor to the Game class initializing Base the same way.
Do not forget to reset the game pointer to 0 when the game object is destroyed. This way, other objects will notice if the game has been yanked away from underneath...
Instructors will verify that the person who has developed the least number of changes is doing this one.
% aerm baseline/test/*.C baseline/test/00/*
In the lecture, I described the
const keyword. Now is the time to use it and to get rid of
all those compiler warnings. Please do not attempt to change anything
else in your code except for adding const
keywords. Instructors will reject changes that modify anything
else. Instructors will also reject changes that will produce compiler
warnings, or that are missing const keywords in essential places.