i want more details abt virtual inheritance in c++

Recommended Answers

All 2 Replies

why don't you search for a C++ tutorial?!

Virutal inheritance comes into play when you inherit from two classes
and both of those class inherit from the same base class. Its called
the diamond shape inheritance.

Here is an example :

struct Base{
};
struct A : Base{
};
struct B : Base{
}
struct C : A , B{
}

The struct C has a problem. Namely that struct A and B inherit from
the same base class. This is not good since it will have 1 more base
class than it needs. So to solve this problem, we need to use virtual inheritance.

So :

struct Base{
};
struct A : Base{
};
struct B : Base{
}
struct C : virtual A , virtual B{
}

Now C contains, A, B and Base. Instead of A,B,Base,Base.
Thats the overview of why one would use virtual inheritance. Google
it up for more info.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.