Es gibt diesen Code:Brace Initialisierung für die Klasse mit virtueller Funktion
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;
}
Warum Initialisierung für variable a
funktioniert, aber nicht für variable b
?
Brace-Initialisierung funktioniert nur für POD-Typen; Machen Sie Ihre Methode virtuell macht es nicht-POD – antlersoft
[Was sind Aggregate und Pods und wie/warum sie besonders sind] (http://stackoverflow.com/questions/4178175/what-are-aggregates-and-pods-and-how -White-sind-sie-speziell) –