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

Is multimap sorted c++?

551


Is it possible to have a recursive inline function in c++?

538


What is ostream in c++?

561


what you know about c++?

652


What is c++ iterator?

631






What is a literal in c++?

557


Explain what are the sizes and ranges of the basic c++ data types?

631


Search for: what is pair in c++?

576


When must you use a pointer rather than a reference?

596


Is c++ high level programming language?

666


What is c++ and its features?

564


What is a stack c++?

562


How can you link a c program with a c function?

556


When is the destructor called?

598


What is a manipulative person?

530