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
What are associate containers?
Is python better than c++?
Can c++ be faster than c?
Why use of template is better than a base class?
What happens when you make call 'delete this;'?
What is a singleton c++?
What are c++ manipulators?
Can char be a number c++?
Will this c++ program execute or not?
Does std endl flush?
What are the classes in c++?
. If employee B is the boss of A and C is the boss of B and D is the boss of C and E is the boss of D. Then write a program using the Database such that if an employee name is Asked to Display it also display his bosses with his name. For eg. If C is displayed it should also display D and E with C?
What are the advantages of inheritance in c++?
what are the decision making statements in C++? Explain if statement with an example?
What is the difference between new() and malloc()?