类布雷斯初始化有此代码:与虚函数
struct A {
int x;
void f() {}
};
struct B {
int y;
virtual void f() {}
};
A a = {2};
//B b = {3}; error: no matching constructor for initialization of 'B'
int main() {
return 0;
}
为什么初始化变量a
作品,但不是变量b
?
Brace初始化仅适用于POD类型;使你的方法虚拟化使它非POD – antlersoft
[什么是聚合和荚以及它们是如何/为什么它们是特殊的](http://stackoverflow.com/questions/4178175/what-are-aggregates-and-pods-and-how为什么他们特别) –