What is Virtual Inheritance?
Answers were Sorted based on User's Feedback
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 |
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 |
Answer / achal ubbott
The concept of virtual inheritance was evolved to avoid
ambiguity/duplication.
e.g.
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 ? | 5 Yes | 1 No |
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 |
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..
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 |
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 |
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 |
How one would use switch in a program?
what is the diff b/n c and c++ a. dynamic scoping b. nested switching c. declaration of variables in any code block d. separation of compilation and linking
What is the purpose of the "delete" operator?
What is the difference between #define debug 0 and #undef debug?
Explain stack & heap objects?
What is the difference between an external iterator and an internal iterator?
How many types of comments are there in c++?
Difference between delete and free.
Why namespace is used in c++?
1. What does the following do: void afunction(int *x) { x=new int; *x=12; } int main() { int v=10; afunction(&v); cout<<v; } a) Outputs 12 b) Outputs 10 c) Outputs the address of v
Read the following program carefully and write the output of the program. Explain each line of code according to given numbering. #include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <errno.h> 1……………… int main (void) { pid_t pid; 2………………………… pid = fork(); 3…………………………. if (pid > 0) { int i; 4………………………… for (i = 0; i < 5; i++) { 5………………… …………… printf(" I AM VU : %d\n", i); 6………………… …………… sleep(1); } exit(0); } 7………………… ……… else if (pid == 0) { int j; for (j = 0; j < 5; j++) { 8……………………………… printf(" I have no child: %d\n", j); sleep(1); } _exit(0); } else { 9………………………………fprintf(stderr, "can't fork, error %d\n", errno); 10……………… … ………… exit (EXIT_FAILURE); } }
What is a breakpoint?