What is a virtual base class?

Answer Posted / atul jawale

Virtual base class is a base class acts as an indirect base
for more than one without duplication of its data members.

A single copy of its data members is shared by all the base
classes that use it as a virtual base.

For example:
A
/ \
B C
\ /
D

class A { /* ... */ }; // indirect base class
class B : virtual public A { /* ... */ };
class C : virtual public A { /* ... */ };
class D : public B, public C { /* ... */ }; // valid

Using the keyword virtual in this example ensures that an
object of class D inherits only one subobject of class A.

Is This Answer Correct ?    75 Yes 7 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What does I ++ mean in c++?

583


Are c and c++ different?

537


What is long in c++?

735


What is oops concept with example?

574


What kind of problems can be solved by a namespace?

591






In what situations do you have to use initialization list rather than assignment in constructors?

631


What is encapsulation in ict?

606


Why do we learn c++?

527


Explain the static storage classes in c++.

703


What is a type library?

684


How to get the current position of the file pointer?

554


Is rust better than c++?

602


What is oops with example?

562


How do you establish an is-a relationship?

616


Is map ordered c++?

592