i have seen an inheritance statement like this

className : virtual public anotherClassName

what does virtual mean there?

Recommended Answers

All 8 Replies

It's to solve the diamond inheritance problem where you have a base class, then 2 child classes then a 4th class that inherits from both of the previous classes. If the base class declares a function then there is ambiguity of that function in the 4th class. Declaring the 2 child classes as inheriting virtually will allow the implementation of the base class's to fall through to the 4th class.

thank you guys i have read it before, but this is the first time i see it in action.

being able to inherit from more than one classes does not seem to be useful, that might be why it is not possible in C# or JAVA

being able to inherit from more than one classes does not seem to be useful, that might be why it is not possible in C# or JAVA

Heh, that's a whole 'nother thread to talk about the benefits, caveats and downfalls of multiple inheritance. Suffice it to say that it's definitely a bonus that C++ has it (sometimes)

being able to inherit from more than one classes does not seem to be useful, that might be why it is not possible in C# or JAVA

Well, Money == Evil, that's why there are lots of paupers in the World ;)...

Well, Money == Evil, that's why there are lots of paupers in the World ;)...

i didnt get it :( (probably language deficiency)

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.