What is Virtual Inheritance?

Answers were Sorted based on User's Feedback

What is Virtual Inheritance?..

Answer / swetcha

Virtual inheritance is used to avoid multiple copies of a
base class in a multiple-inherited object. However, there
are cases where multiple copies of a base are needed in a
derived class. In such cases, virtual inheritance is
intentionally avoided

Is This Answer Correct ?    18 Yes 2 No

What is Virtual Inheritance?..

Answer / rakesh kumar

whenever there are two derived class derived from same base
class,when these two derived classes derive third derived
class which contain the properties of the 1st base class
twice.virtual class is use to avoid this.

Is This Answer Correct ?    5 Yes 1 No

What is Virtual Inheritance?..

Answer / achal ubbott

The concept of virtual inheritance was evolved to avoid

class base
int value;
now we do some multiple inheritance
class A:public base {};
class B:public base {};

Now value is member to both the classes A and B.
Lets have a class C that inherits from both A and B.
class C:public A, public B {};

Now should that mean that C have 2 copies of value as its
data member? Yes and this leads to ambiguity.
So do like this

class C:virtual public A,virtual public B {};

Is This Answer Correct ?    4 Yes 1 No

What is Virtual Inheritance?..

Answer / shivachinna

virtual concept is uaed to avoid confusions with same name
of methods in super class as well as sub class.....

Is This Answer Correct ?    0 Yes 0 No

What is Virtual Inheritance?..

Answer / 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..


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

What is Virtual Inheritance?..

Answer / sandeep mannarakkal

Virtual inheritance is used for creating an a class (portion in the derived object ) as first. Once this object portion got created then compiler insert a offset to the remaining portion of the object for identifying the virtual portions.

Is This Answer Correct ?    0 Yes 0 No

What is Virtual Inheritance?..

Answer / sharukh khan

Totally wrong answer !
you are fail man !
read some more books !

please read books guys , websites cheats you !

Is This Answer Correct ?    3 Yes 17 No

Post New Answer

More C++ General Interview Questions

what is the behaviour of C and C++ compiler for the below statements. int *p; p = malloc(100); Is the behaviour same ? or different ?

2 Answers  

Explain the ISA and HASA class relationships. How would you implement each in a class design?

2 Answers  

why and when we can declar member fuction as a private in the class?

0 Answers  

Write a program which is required to process the time of a clock in hours and minutes, entered from the keyboard. With this program, there are two requirements for any data entered by a user: 1. The data must be of the correct type (in this case, two ints). 2. The data must be in the correct range: this means that, for the minutes, negative numbers and any number above 59 must be rejected; for the hours, negative numbers and any number above 23 must be rejected. Output error message for invalid data input. Output the time one and a half hour after the time input. i.e. Hour: 22 Min: 32 One and a half hour after 22:32 is 00:02

0 Answers  

Implement a 2 dimensional array by one dimentional array

1 Answers   CTS,

Difference between Top down and bottom up approaches for a given project ?

14 Answers   Siemens, Infosys, HCL, CSC, HP, IIT, BSNL,

What is the difference in size of this two clasees? Class A { int a; char c; float f; } Class B { float f; char c; int a; }

4 Answers  

check whether a no is prime or not.

3 Answers   TCS,

program explaining feautures of c++

0 Answers   Satyam,

Can we have "Virtual Constructors"?

10 Answers   TCS,

When is a template better solution than a base class??

2 Answers   emc2,

"How will you merge these two arrays? Write the program Array: A 1 18 22 43 Array: B 3 4 6 20 34 46 55 Output Array: C 1 3 4 6 18 20 22 34 43 46 55"

9 Answers   HCL, College School Exams Tests,