我从这个维基百科页面复制了以下示例:
struct BasicStruct {
int x;
double y;
};
struct AltStruct {
AltStruct(int x, double y) : x_{x}, y_{y} {}
private:
int x_;
double y_;
};
BasicStruct var1{5, 3.2};
AltStruct var2{2, 4.3};
int main (int argc, char const *argv[])
{
return 0;
}
然后我尝试用
clang++ -Wall -std=c++11 test.cpp
但我收到此错误:
test.cpp:17:11: error: non-aggregate type 'AltStruct' cannot be initialized with
an initializer list
AltStruct var2{2, 4.3};
^ ~~~~~~~~
1 error generated.
我的clang版本clang++ --version
是
Apple clang version 3.1 (tags/Apple/clang-318.0.61) (based on LLVM 3.1svn)
Target: x86_64-apple-darwin11.4.0
Thread model: posix
这个例子不应该工作吗?也许clang还不是完全兼容c++11?
这是怎么回事?