- Feature Articles
- CodeSOD
- Error'd
-
Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Virtual inheritance is a solution to a problem you shouldn't have in the first place. There probably are some very niche problems where this is the best solution, but in general the need for virtual inheritance is an indication your class hierarchy needs looking at with a very critical eye.
Admin
Well, it does virtually nothing...
Edit Admin
It's not, as such, a workaround, but an actual solution. And unless you can redesign your class hierarchy to eliminate the diamond (e.g. in the example given, by making one or both of B or C not inherit from A), (as far as I know) virtual inheritance is not "one workaround", but, in fact, the only solution.
But in general virtual inheritance should be avoided almost at all costs, and multiple inheritance should be mostly avoided. In C++, it's still allowed by the language, and multiple inheritance is required to do interface-implementation split development ("implements" in Java terms). Java allows at most one "extends" inheritance, and as many "implements" inheritances as you need, but C++ has only "extends" inheritance. That means that the C++ programmer must manually construct the interface classes to be completely pure-virtual with no data members, and to have no concrete implementations of any function except the destructor, which might as well, in C++11+, be
~ClassName() = default;because it has exactly nothing to do.