FAQ 17.07 How can a class Y be a kind-of another class X as well as getting the bits of X?This is easy: use public inheritance. Here is the C++ syntax for public inheritance. class X { /*bits and/or code go here*/ }; class Y : public X { /*more bits and/or code go here*/ }; This does two distinct things. First, it provides the kind-of relationship: Y is a kind-of X, therefore Y supports the same services as X (Y might add some new member functions as well). Second, it shares bits and code: Y inherits X's bits (data structures) and code (algorithms). |