c++ - Brace initialization for class with virtual function -


there code:

struct {    int x;    void f() {} };  struct b {    int y;    virtual void f() {} };  a = {2};  //b b = {3}; error: no matching constructor initialization of 'b'  int main() {    return 0; } 

why initialization variable a works not variable b?

a aggregate, , can have brace initialization, , b isn't, since has virtual method.

8.5.1 aggregates

an aggregate array or class (clause 9) no user-provided constructors (12.1), no brace-or-equal- initializers non-static data members (9.2), no private or protected non-static data members (clause 11), no base classes (clause 10), , no virtual functions (10.3).


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -