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 java as fast as c++?

595


Write a program that takes a 5 digit number and calculates 2 power that number and prints it.

2064


How can a called function determine the number of arguments that have been passed to it?

655


why is c++ called oops? Explain

578


Can a class be static in c++?

561






What is the difference between a declaration and a definition?

579


What is object in c++ wikipedia?

566


Will a catch statement catch a derived exception if it is looking for the base class?

554


Can we inherit constructor in c++?

582


How can you prevent accessing of the private parts of my class by other programmers (violating encapsulation)?

637


What are arithmetic operators?

531


Explain selection sorting?

637


What does #define mean in c++?

604


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

559


What are the advantages of prototyping?

560