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

Write a C++ Program to check whether a number is prime number or not?

638


If dog is a friend of boy, is boy a friend of dog?

575


What is a pointer with example?

662


What is data hiding c++?

601


Can you please explain the difference between overloading and overriding?

603






Differentiate between late binding and early binding. What are the advantages of early binding?

586


Write a program to find the Fibonacci series recursively.

612


What is the use of endl in c++ give an example?

618


Explain rethrowing exceptions with an example?

611


What is the use of dot in c++?

625


What is this weird colon-member (" : ") syntax in the constructor?

547


What is c++ programming language?

581


Where is atoi defined?

584


What is c++ runtime?

659


What is the array and initializing arrays in c++?

509