Calling a virtual base class's overloaded constructor

后端 未结 4 1108
孤城傲影
孤城傲影 2021-01-11 16:42

Is there a (practical) way to by-pass the normal (virtual) constructor calling order?

Example:

class A
{
    const int i;

public:
          


        
4条回答
  •  甜味超标
    2021-01-11 16:52

    I understand why C has to call the ctor of A (ambiguity) when you instanciate C, but why does D have to call it when instanciating D?

    For the same reason that C has to call it. It's not an issue of ambiguity, it's the fact that A's constructior must be called only once (since it's a virtual base).

    If you were hoping that C might be able to initialise A's constructor then what if class D were to inherit C and another class that ultimately inherits A?

提交回复
热议问题