What is a virtual base class?

Answer Posted / ragib nasir ahmed

A virtual base class is one in which only one copy of the
base class is inherited to the derived class.
Let us consider the classes A,B,C,D
class A
{
int a;
public:
void geta(void)
{
a=10;
}
};
class B: public virtual A
{
int b;
public:
void getb(void)
{
b=20;
}
};
class C:virtual public A
{
int c;
public:
void getc(void)
{
c=30;
}
};
class D:public B,public C
{
public:
void display(void)
{
cout<<a<<b<<c<<d;
}
};

Is This Answer Correct ?    25 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is inheritance in oop?

597


What are guid? Why does com need guids?

566


Differentiate between C and C++.

705


How many times will this loop execute? Explain your answer.

374


What are two types of polymorphism?

607






Which one between if-else and switch is more efficient?

600


What is a catch statement?

579


Is c++ used anymore?

582


What is the most useful programming language?

601


What is an inline function in c++?

624


What is a block in c++?

546


Why c++ does not have finally?

585


Why do we use structure in c++?

570


Explain the differences between private, public and protected and give examples.

564


what is oops and list its features in c++?

542