Is this legal c++0x syntax?
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>() );
}
Because if so, I just found a bug in GCC 4.6.
The error I get is:
error: expected primary-expression before '{' token
which is ... logical ... if it was illegal.
UPDATE: As @Kerrek has illustrated, this bleeds into plain C++03, with aggregates and the old brace initialization syntax for them. Why is this not possible? Is it forbidden in the Standard? Or are compilers at fault? Or is this an oversight? I don't see any serious problems in allowing this as an alternative to explicitely calling the constructor.
It is valid in C++11, but it was a very late addition to the working paper that Bjarne put through. So it's not surprising that GCC doesn't support brace default arguments yet.
来源:https://stackoverflow.com/questions/6615823/uniform-initializer-used-in-default-argument-to-const-reference