为什么不能将初始化器列表用作参数? [英] Why can an initializer-list not be used as an argument?

查看:181
本文介绍了为什么不能将初始化器列表用作参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  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(11月CTP)报告:



 错误C2664:'int f(const X&)':无法将参数1从
'initializer-list'转换为'X'

原因:无法从'initializer-list'转换为'X'
只有具有零个或一个元素的初始化器列表可以转换为此类型

Build失败。


解决方案


Visual Studio 2012 11 CTP)报告:


这甚至不是一个测试版的编译器。它应该工作。我会链接到你的代码使用的ideaone,但这个网站不会让这样做。



提交bug报告。


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) reports:

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:

It's not even a beta compiler. It's supposed to work. I'd link to your code working on ideaone, but this website won't let be do that.

File a bug report on it.

这篇关于为什么不能将初始化器列表用作参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆