【发布时间】:2017-12-13 01:22:47
【问题描述】:
我有以下程序:
#include<iostream>
using namespace std;
struct Base01{
int m;
Base01():m(2){}
void p(){cout<<m<<endl;}
};
struct Derived01:public Base01{
Derived01():m(3){}
};
struct Derived02:virtual public Base01{
Derived01():m(4){}
};
struct my: Derived01,Derived02{
my():m(5){}
};
int main(){
return 0;
}
gcc/clang 都报编译错误。
我只是想知道这里的语言设计考虑是什么,为什么派生类只能在初始化列表中调用基类ctor,而不能直接使用基类成员?
【问题讨论】:
标签: c++ list class initialization derived