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
Can I learn c++ in a week?
How should a contructor handle a failure?
What is a hash function c++?
How much do coding jobs pay?
What is difference between c++ 11 and c++ 14?
Difference between declaration and definition of a variable.
When is dynamic checking necessary?
What does the linker do?
Which sort does c++ use?
Is map thread safe c++?
What is the use of "new" operator?
What is ifstream c++?
What are pointers, when declared, intialized to a) NULL b) Newly allocated memory c) Nothing. Its random
Why do we use setw in c++?
In which situation the program terminates before reaching the breakpoint set by the user at the beginning of the mainq method?