InterviewSolution
| 1. |
What Is Virtual Multiple Inheritance? |
|
Answer» Answer :A class b is defined having MEMBER variable i. Suppose two classes d1 and d2 are derived from class b and a class multiple is derived from both d1 and d2. If variable i is ACCESSED from a member function of multiple then it gives ERROR as 'member is ambiguous'. To avoid this error derive classes d1 and d2 with modifier virtual as shown in the following program. #include class b { public : int i ; public : fun( ) { i = 0 ; } } ; class d1 : virtual public b { public : fun( ) { i = 1 ; } } ; class d2 : virtual public b { public : fun( ) { i = 2 ; } } ; class multiple : public d1, public d2 { public : fun( ) { i = 10 ; } } ; void MAIN( ) { multiple d ; d.fun( ) ; cout << d.i ; } |
|