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
Is java as fast as c++?
Write a program that takes a 5 digit number and calculates 2 power that number and prints it.
How can a called function determine the number of arguments that have been passed to it?
why is c++ called oops? Explain
Can a class be static in c++?
What is the difference between a declaration and a definition?
What is object in c++ wikipedia?
Will a catch statement catch a derived exception if it is looking for the base class?
Can we inherit constructor in c++?
How can you prevent accessing of the private parts of my class by other programmers (violating encapsulation)?
What are arithmetic operators?
Explain selection sorting?
What does #define mean in c++?
How can you link a c program with a c function?
What are the advantages of prototyping?