Why only base class default constructor is called in virtual base multiple inheritance? [duplicate]

风流意气都作罢 提交于 2019-12-01 07:17:49

The virtual base is constructed by the most-derived object. So AB's constructor call the Base constructor, but since you didn't specify a constructor for AB, its default constructor just calls the default constructor of Base.

You could call the string-constructor from AB like this:

struct AB : A, B
{
    AB() : Base("hello"), A(), B() { }
};

Note that the constructors A::A() and B:B() do not call the Base constructor in this setup!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!