10.8 Overriding Functions


10.8 Overriding Functions

As demonstrated, new classes can inherit from other classes. The new class becomes the derived class and the older class is called the ancestor class. The ancestor class may have had a number of different methods, and it is possible for the derived class to redefine those methods, overriding them. To do this, the derived class simply needs to create a method whose declaration and scope is the same as that of the ancestor class. Considering the following code:

      class Frog      {         int Color;         int Height;         int Width;      public:         void Jump();         void Sleep();         void Eat();         int operator+(Frog param);    //Defines Add Operator         int operator-(Frog param);    //Defines Add Operator      };      class FlyingFrog : public Frog      {         public:            void Eat();      }; 




Introduction to Game Programming with C++
Introduction to Game Programming with C++ (Wordware Game Developers Library)
ISBN: 1598220322
EAN: 2147483647
Year: 2007
Pages: 225
Authors: Alan Thorn

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net