Google
 
   
Login
Username:

Password:


Lost Password?

Register now!
Search
Main Menu
top books
Polls
What do you think about php-deluxe.net?
Excellent!
Cool
Hmm..not bad
What the hell is this?
encyclopedia
recommendation
compare webbrowser
Freenet DSL
Who's Online
6 user(s) are online (5 user(s) are browsing encyclopedia)

Members: 0
Guests: 6

more...
browser tip
Unix Befehle
manual of unix befehle
recommendation!
Sponsored
partner

Virtual inheritance

In object-oriented programing languages, virtual inheritance solves some of the problems caused by multiple inheritance by having common grandparent classes used only once. It usually is used when the inheritance is representing restrictions of a set rather than composition of parts.

In C plus plus, virtual inheritance is indicated by the virtual keyword. For example:

class Animal { virtual void Eat(); }; // Two classes virtually inheriting TheCommonBase: class Mammal : public virtual Animal { virtual const Color GetHairColor() const; }; class WingedAnimal : public virtual Animal { virtual void Flap(); }; // A bat can Eat class Bat : public Mammal, public WingedAnimal {};

In the above, if Mammal and WingedAnimal did not inherit virtually, a call to Bat::Eat() would be ambiguous and hence a compile error.