类初始化parens使用

Geo*_*tis 2 c++ c++11

我想初始化一些类成员,并且"expected parameter declarator"在使用g ++时我得到错误 (使用clang ++)"expected identifier before numeric constant". 所以我再次读取类初始化并编写下面的代码:

#include <stdio.h>    
class AAA{
public:
    int l;
    AAA(int i){l=i;}
};

class BBB{
    bool normal;
    AAA aaa=10;
    AAA bbb(20);
    AAA ccc{30};
    AAA ddd={45};
};

int main(int argc, char **argv){printf("hello world\n");return 0;}
Run Code Online (Sandbox Code Playgroud)

看来语法AAA bbb(20)不被接受!

这是正常的吗?(我使用选项-std = c ++ 11).

或者我错过了一些观点?

jua*_*nza 8

这个是正常的.C++ 11不允许()在非静态数据成员的就地初始化中使用括号.这是为了避免潜在的解析作为函数.您可以使用()以下语法使用perantheses:

AAA bbb = AAA(20);
Run Code Online (Sandbox Code Playgroud)

因为此表单无法解析为函数.