I'm new to object oriented programming and am struggling a bit with how best to write classes.
I am trying to abstract the idea of sorting to objects that are not just lists of numbers. I have an abstract base class, SortableContainer
, which contains all the necessary virtual functions for comparing and swapping elements, along with some overloaded operators. I then have two classes derived from that, MVector
and CoordinateArray
. Both of these derived classes have proper definitions for all the virtual functions in the base class. Everything up to this point has worked just fine. MVector
just stores vector-like objects and CoordinateArray
stores vectors of coordinates onto which a notion of 'less than' has been defined.
My problem now is that I have created a new class, Life
, which I want to use to implement the game of life using a CoordinateArray
object to store the alive cells. The outline of my Life
class looks like this:
class Life
{
public:
CoordinateArray LiveCells;
Life();
};
When I create a Life object and initialise it with the coordinates of some alive cells, none of the member functions defined in the CoordinateArray
derived class will work. How can I fix this? Do I have to derive the Life
class from the SortableContainer
class and then override all the pure virtual functions? Any help or direction to help will be much appreciated.