具有“在类成员初始化”特性制作成C ++ 11? [英] Has "In class member initialization" feature made into C++11?

查看:154
本文介绍了具有“在类成员初始化”特性制作成C ++ 11?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在课程初始化功能中,允许在类本身内初始化普通成员,

In class initialization feature, which allows to initialize normal members inside the class itself,

struct A {
  int a = 0; // error: ISO C++ forbids in-class initialization of non-const static member ‘a’
};

这是最新编译器gcc-4.6的错误( -std = c ++ 0x )。在C ++ 11标准或gcc中的此功能是否仍然不支持它?

This is giving error in latest compiler gcc-4.6 (with -std=c++0x). Has this feature made into the C++11 standard or gcc still doesn't support it ?

推荐答案

在C ++ 0x。在N3290§12.6.2/ 8有一个例子:

Yes, that is legal in C++0x. There is an example of this at N3290 §12.6.2/8:

struct C {
    /* ... */
    int j = 5; // OK: j has the value 5
};

这篇关于具有“在类成员初始化”特性制作成C ++ 11?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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