initializer_list在VC10中不工作 [英] initializer_list not working in VC10
问题描述
hi
i在VC ++ 2010中撰写此程式:
hi i wrote this program in VC++ 2010:
class class1
{
public:
class1 (initializer_list<int> a){};
int foo;
float Bar;
};
void main()
{
class1 c = {2,3};
getchar();
}
但我得到这个错误,当我编译项目:
but i get this errors when i compile project:
错误1错误C2552:'c':
无法初始化非聚合
with initializer
list c:\ users\pswin\documents\visual
studio
2010\projects\test_c ++ 0x\test_c ++ 0x\main.cpp 27
Error 1 error C2552: 'c' : non-aggregates cannot be initialized with initializer list c:\users\pswin\documents\visual studio 2010\projects\test_c++0x\test_c++0x\main.cpp 27
和
2 IntelliSense: 。}'不允许用于
的对象类型
class1c:\users\pswin\documents\visual
studio
2010 \projects\ test_c ++ 0x\test_c ++ 0x\main.cpp 27
2 IntelliSense: initialization with '{...}' is not allowed for object of type "class1" c:\users\pswin\documents\visual studio 2010\projects\test_c++0x\test_c++0x\main.cpp 27
有什么问题?
推荐答案
It shouldn't be supported at all:
[... ]初始化列表的C ++ 0x核心语言特性和相关的标准库更改在VC10中未实现。
[...] the C++0x Core Language feature of initializer lists and the associated Standard Library changes weren't implemented in VC10.
错误消息是指聚合初始化的前C ++ 0x功能,它允许通过使用大括号来初始化某些用户定义的类型:
The error message refers to the pre-C++0x feature of aggregate initialization, which allows the initialization of certain user-defined types by using curly braces:
struct pair { int first; char second; };
pair p = { 0, 'c' };
总计在§8.5.1中定义:
聚合是数组或类(第9节),没有用户声明的构造函数(12.1),没有私有或受保护的非静态数据成员11),没有基类(第10节),没有虚函数(10.3)。
An aggregate is an array or a class (clause 9) with no user-declared constructors (12.1), no private or protected non-static data members (clause 11), no base classes (clause 10), and no virtual functions (10.3).
初始化聚合时,初始化程序可以包含一个initializer-clause,包含一个括号括起来的逗号分隔的聚合成员的初始化子句列表,以增加下标或成员顺序写。如果聚合包含子聚合,则此规则将递归应用于子聚集的成员。
When an aggregate is initialized the initializer can contain an initializer-clause consisting of a brace- enclosed, comma-separated list of initializer-clauses for the members of the aggregate, written in increasing subscript or member order. If the aggregate contains subaggregates, this rule applies recursively to the members of the subaggregate.
这篇关于initializer_list在VC10中不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!