Page 195 - DCAP404 _Object Oriented Programming
P. 195

Object-oriented Programming




                    Notes              public:
                                           void  Chirp()const  {  Whinny();  }
                                           Pegasus(COLOR,  HANDS,  bool,  long,  int);
                                           virtual  ~Pegasus()  {cout  <<  "Pegasus  destructor...\n";}
                                           virtual  long  GetNumberBelievers()  const
                                           {  return    itsNumberBelievers;  }
                                           virtual  COLOR  GetColor()const  {  return  Horse::itsColor;  }

                                           virtual  int  GetAge()  const  {  return  Horse::GetAge();  }
                                       private:
                                           long  itsNumberBelievers;
                                   };


                                   Pegasus::Pegasus(
                                         COLOR  aColor,

                                         HANDS  height,
                                         bool  migrates,
                                         long  NumBelieve,
                                         int  age):
                                         Horse(aColor,  height,age),
                                         Bird(aColor,  migrates,age),
                                         itsNumberBelievers(NumBelieve)
                                   {
                                         cout  <<  "Pegasus  constructor...\n";

                                   }


                                   int  main()
                                   {
                                         Pegasus  *pPeg  =  new  Pegasus(Red,  5,  true,  10,  2);
                                         int  age  =  pPeg->GetAge();
                                         cout  <<  "This  pegasus  is  "  <<  age  <<  "  years  old.\n";

                                         delete  pPeg;
                                         return  0;
                                   }



                                     Did u know?  How the ambiguities in multiple inheritance are removed?
                                     You can also avoid this ambiguity by using the base specifier virtual to declare a base class





          188                               LOVELY PROFESSIONAL UNIVERSITY
   190   191   192   193   194   195   196   197   198   199   200