c – 为什么初始化列表不能用作参数?

struct X
{
    int a;
    int b;
};

int f(X x)
{
    return x.a + x.b;
}

int main()
{
    int n = f({1, 2});
}

Visual Studio 2012(Nov CTP)报告:

error C2664: 'int f(const X &)' : cannot convert parameter 1 from
'initializer-list' to 'X'

Reason: cannot convert from 'initializer-list' to 'X'
Only an initializer-list with zero or one elements can be converted to this type

Build FAILED.

最佳答案

Visual Studio 2012 (Nov CTP) reports:

它甚至不是beta编译器.它应该工作.我会链接到你在ideaone上工作的代码,但是这个网站不会这样做.

提交有关它的错误报告.

点赞