このコードがあります:なぜ初期化変数a
作品のためではなく、変数b
ためブレースの初期化
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;
}
は?
ブレースの初期化は、PODタイプでのみ機能します。あなたのメソッドをバーチャルにすることは、POD以外のものになります – antlersoft
[集約とポッドとは何ですか、そしてそれらがどのように特殊なのか/なぜですか?](http://stackoverflow.com/questions/4178175/what-are-aggregates-and-pods-and-how -why-are-they-special) –