class myOldClass { variables + functions ... } class myNewClass public : public myOldClass { more variables + more functions ... } |
class myOldClass { public: int i1; void func1(int i) { i1 = i1 + i; } }; |
class myNewClass : public myOldClass { public: int i2; void func2(int i) { i2 = i2 - i; } }; |
It is as though we have defined myNewClass as follows:
class myNewClass { public: int i1; int i2; void func1(int i) { i1 = i1 + i; } void func2(int i) { i2 = i2 - i; } }; |
The way to do that should be obvious; and I will not spend much time dwelling on examples.
Before we can understand how such program can be written, I need to discuss function polymorphism first.