在const参数的默认参数中使用的统一初始值设定项

rub*_*nvb 5 c++ uniform-initialization c++11

这是合法的c ++ 0x语法吗?

class A
{
public:
    void some_function( const std::set<std::string> &options = {} );
    // note that this is legal, which binds the const reference to a temporary:
    void some_function( const std::set<std::string> &options = std::set<std::string>() );
}
Run Code Online (Sandbox Code Playgroud)

因为如果是这样,我刚刚在GCC 4.6中发现了一个错误.

我得到的错误是:

错误:在'{'标记之前预期的primary-expression

这是......逻辑......如果它是非法的.

更新:正如@Kerrek所说明的那样,这会渗透到普通的C++ 03中,并带有聚合和旧的大括号初始化语法.为什么这不可能?是否禁止使用标准?或编译器有错?或者这是疏忽吗?我没有看到任何严重的问题,允许它作为明确调用构造函数的替代方法.

Joh*_*itb 7

它在C++ 11中有效,但它是Bjarne完成的工作文件的一个非常晚的补充.因此,GCC不支持大括号默认参数也就不足为奇了.