Corey Roth and Friends Blogs

Group site for developer blogs dealing with (usually) Ionic, .NET, SharePoint, Office 365, Mobile Development, and other Microsoft products, as well as some discussion of general programming related concepts.

Not Necessarily Dot Net

October 2010 - Posts

  • C++ Virtual Inheritance

    I don't know what the odds are that anyone actually having this problem will run across this on google. But maybe someone will read it and remember before-hand.

    I have an inheritance hierarchy something like

    Interface -> ABC -> C -> D.

    Each constructor explicitly calls its parent class' constructor, with the appropriate parameter.

    Originally, ABC had a default parameter to its constructor. Things just weren't working right, and I noticed that the constructors were getting called out of order. ABC was getting called first, with the default parameter, then Interface, C, and D. When I got rid of the default parameter, D (and all its siblings) quit compiling because ABC didn't have a default constructor.

    After a great deal of frustration and trying to isolate the problem, I realized that C was inheriting virtually from ABC. I think I was planning on it being a mixin with other classes that also inherit from ABC. (This project has no architecture or up-front planning. It's cowboy-coding at its finest. And C++ is the wrong language for that).

    I don't know whether this is a C++ bug or just part of the standard that I missed, and I've already wasted *way* too much time on it. Hopefully this will help someone else avoid making the same mistake.

Powered by Community Server (Non-Commercial Edition), by Telligent Systems