problems with multiple inheritancethe following


Problems With Multiple Inheritance

The following example presents a problem with multiple inheritance.

class Aclass

 {

  public :

 void put()

                                 {

                                                :

                                 }

};

class  Bclass

 {

   public :

void put()

 {

                :

                                 }

 };

class Cclass : public Aclass , public Bclass

 {

  public  :

                                                :

                                                :

 };

                void main()

                 {

                  A objA;

                  B objB;

                  C objC;

 

objA.put();     // From Class A

objB.put();          // From class B

objC.put();          // AMBIGUOUS -RESULTS IN ERROR

                 }

The above example has a class C derived from two classes A and B. Both these classes have a function with the similar name - put(), which suppose, the derived class does not have. The class C inherits the put() function from both the classes. When a call to this function is made using the object of the derived class , the compiler does not know which class it is referring to. In this case, the scope resolution operator has to be used to state the correct object . Its usage is very simple. The statement giving an error from the above instance has to be replaced with the following :

 

                objC.A::put();    // for class A

                objC.B::put();    // for class B

 

Request for Solution File

Ask an Expert for Answer!!
C/C++ Programming: problems with multiple inheritancethe following
Reference No:- TGS0309453

Expected delivery within 24 Hours