Illustrate the problems with multiple inheritance, C/C++ Programming

Assignment Help:

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

 


Related Discussions:- Illustrate the problems with multiple inheritance

Minimum shelf, At a shop of marbles, packs of marbles are prepared. Packets...

At a shop of marbles, packs of marbles are prepared. Packets are named A, B, C, D, E …….. All packets are kept in a VERTICAL SHELF in random order. Any numbers of packets with thes

Is there anything you can do in c++ which you cannot do in c, A: No. There ...

A: No. There is nothing you can do in C++ which you cannot do in C. In spite of everything

Operator overloading, Op e r a t o r O v e r l o a d i n g :...

Op e r a t o r O v e r l o a d i n g : W h e n   a n   o p e r a t o r   i s   u s e d   f o r   d i ff e r e n t   op e r a

Write a program that computes the cost of a long distance ca, Write a progr...

Write a program that computes the cost of a long distance call. The cost of the call is determined according to the following rate schedules. a. A call made between 8:00 AM and 6:

What is scope resolution operator, Scope Resolution operator: The scope...

Scope Resolution operator: The scope resolution operator: : is used to access global variable in the inner block. When global and local variable are identical name the scope re

Explain the loop statements in computer programming, Explain the Loop State...

Explain the Loop Statements in Computer Programming? 1. C gives you a choice of three kinds of loop, while, do while and for. 2. The while loop remain repeating an action until

C program that controls the uart, Objective: Construct a C program tha...

Objective: Construct a C program that controls the UART, and is capable of displaying strings. Echo characters received on the UART to the LCD screen Outcome: A mess

Luminous Jewels - The Polishing Game, plaese tell the full program for the ...

plaese tell the full program for the above given topic with the input and output

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd