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

Can I learn c++ in a week?

576


How should a contructor handle a failure?

683


What is a hash function c++?

550


How much do coding jobs pay?

546


What is difference between c++ 11 and c++ 14?

572






Difference between declaration and definition of a variable.

585


When is dynamic checking necessary?

597


What does the linker do?

587


Which sort does c++ use?

576


Is map thread safe c++?

628


What is the use of "new" operator?

655


What is ifstream c++?

553


What are pointers, when declared, intialized to a) NULL b) Newly allocated memory c) Nothing. Its random

647


Why do we use setw in c++?

639


In which situation the program terminates before reaching the breakpoint set by the user at the beginning of the mainq method?

584