【发布时间】:2011-07-07 19:13:55
【问题描述】:
这是合法的 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>() );
}
因为如果是这样,我刚刚在 GCC 4.6 中发现了一个错误。
我得到的错误是:
错误:“{”标记之前的预期主表达式
这是……合乎逻辑的……如果它是非法的。
更新: 正如@Kerrek 所说明的那样,这会渗透到普通的 C++03 中,并带有聚合和旧的大括号初始化语法。为什么这是不可能的?标准中是否禁止?还是编译器有问题?或者这是一个疏忽?我认为允许将此作为显式调用构造函数的替代方法没有任何严重问题。
【问题讨论】:
标签: c++ c++11 uniform-initialization