. This challenges my understanding of C++ inheritance hierarchies, as I expected this code to compile fine.

My understanding is that

IllegalArgumentException

should compile because, although it is true that

std::runtime_error

does not have a default constructor, its constructor is being called by the constructor for

RuntimeException

. But obviously this must must be false, as the compiler is rejecting it. It seems to want me to call the

std::runtime_error

constructor directly from the

IllegalArgumentException

constructor (the compiler error goes away when I do so), but this seems wrong because then I would be calling the constructor for

std::runtime_error

twice: once in the constructor for

RuntimeException

, and again in the constructor for

IllegalArgumentException

.

Is this safe and/or efficient to do? If not, why does the compiler seem to encourage it? I could just derive from

std::exception

and implement the

std::string

myself as a member variable, but I thought it would be easier to derive from a standard class that has already implemented this. Is this the wrong approach to take? Additionally, is the fact that I'm deriving virtually from both

When using virtual inheritance the constructor call of the virtual base is the responsibility of the most derived class rather than the responsibility of any intermediate class. The reason is obvious: the use of virtual inheritance indicates that there is an expectation that there are actually multiple derived classes using the base class. Which one of these derived classes would be responsible for constructing the virtual base?

So, the constructor of any of the derived classes needs to provide an argument to the virtual base, e.g.:

To avoid having intermediate bases call the constructor of the virtual base classes intended for virtual inheritance often provide a default constructor. Of course, that opens up the possibility that the most derived class incorrectly relies on the proper constructor being called by one of its bases.

Email codedump link for Deriving class from virtual base with no default destructor