I think you might be confusing the ideas of inheritance and containment.
The difference is sometimes called
is-a vs. has-a.
When you inherit a class into a new class, the new class
is-a class of it's ancestoral type.
If you declair objects of type class_2 within the structure of a class_1, that class_1
has-a class_2. That is containment.
An example of inheritance in LaserBoy is the relationship that exists between a ez_uail_segment and an ez_uail_frame. Both of these concepts have the same core information. They both contain a list of ordered points that make up a laser drawing. But a segment is more primative and therefore can be used with greater flexibility. A frame is a much more defined object.
A frame
is-a segment with additional features.
There are a few functions that can be called on the segment type that effect information that is only found in the frame. So if the function is called on a segment, that's fine. But if the same function gets called on a frame object, the frame needs to know. So a virtual function is defined within the frame class that calls the segment function of the same name and does some other stuff the frame needs to do because of the change in data that happened to the segment that is actually its own core. That is an example of a virtual function.
One of the cool tricks that I use in LaserBoy is "containment via inheritance"!
It looks so simple and eligant, but there is a lot going on here!
If I first create a class that is to be an element of an array of things; like an ez_ual_point. I can then use the STL vector class template to make a container of them. But, I can also inherit that container class of vector<ez_uail_point> into a class with a better name and all kinds of added custom functionality; ez_uail_segment..... in one line of code!
//############################################################################
class ez_uail_segment : public vector<ez_uail_point>
{
public: .....
The type vector<ez_uail_point> never gets an object or reference name of its own. It is simply inherited directly into a new class type. So ez_ual_segment
is-a vector<ez_uail_point> with added features. This makes it possible to call all of the functions that are part of the STL vector class upon objects of this type.
I also use multiple inheritance which you can only do in C++!
//############################################################################
class ez_uail_point : public ez_3D_short, public ez_color
{
public: .....
James.