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 virtual functions in c++?
What are c++ storage classes?
Which is the best c++ compiler for beginners?
What is the difference between a reference and a pointer?
Is c++ map a hash table?
Why c++ is the best language?
What are the advantages of using friend classes?
What data encapsulation is in c++?
Do the names of parameters have to agree in the prototype, definition, and call to the function?
Is main a class in c++?
How do I run a program in notepad ++?
Do we have to use initialization list in spite of the assignment in constructors?
What is abstraction with real time example?
Define namespace in c++?
What is the most useful programming language?