What is Virtual Inheritance?

Answer Posted / rama

The duplication of inherited members due to multiple paths can be avoided by making the common base class(ancestor class) as virtual base class..

FOR EXAMPLE

class A //grandparent
{
...
...
};
class B1:virtual public A //parent1
{
...
...
};
class B2:public virtual A //parent2
{
...
...
};
class C :public B1,public B2
{
... //only one copy of A
... //will be inherited
};


When a class is made a virtual base class, it take necessary care to see that only one copy of that class is inherited, regardless of how many inheritance paths exits between the virtual base class and a derived class.

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What does 7/9*9 equal ? a) 1 b) 0.08642 c) 0

583


What is the difference between *p++ and (*p)++ ?

781


Do you know what are the new features that iso/ansi c++ has added to original c++ specifications?

560


Explain the difference between c++ and java.

650


What is the protected keyword used for?

618






Give the difference between the type casting and automatic type conversion. Also tell a suitable C++ code to illustrate both.

634


write a corrected statement so that the instruction will work properly. if (4 < x < 11) y = 2 * x;

1517


When does a name clash occur in c++?

717


What is ios flag in c++?

688


On throwing an exception by the animal constructor in p = new animalq, can memory leak occur?

683


Am pass the 10000 records to target in target I will take commit interval 15000 when I was stop the work flow what will happened

1081


What new()is different from malloc()?

571


What is the last index number in an array of 100 characters a) 100 b) 99 c) 101

590


Should the this pointer can be used in the constructor?

556


What is the main purpose of overloading operators?

592