C ++数组的初始化警告 [英] C++ Array Initializers Warnings

查看:7671
本文介绍了C ++数组的初始化警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经声明并初始化类中的一个常量字符数组:

 类网{
    常量字符测试[11] = {的','E','1','2','3','4','5','6','7','8','9 '};

我的code的工作,但我不断收到编译器警告:

非静态数据成员的初始化仅适用于C ++ 11

扩展初始化仅适用于列表C ++ 11

我知道,这不是一个问题,因为我要编译C ++ 11的标准,但我很好奇,什么是pre C ++ 11关于我的code。

我希望有人可以给我一些见解,并建议我可以做什么,使这个code C ++ 98友好。

同样的要求,我的编译器命令:

 > G ++ -o测试的main.cpp


解决方案

要使它C ++ 98兼容,你需要初始化非静态类的声明之外的类常量。

I have declared and initialized a constant char array within a class:

class grid {
    const char test[11] = {'s', 'e', '1', '2', '3', '4', '5', '6', '7', '8', '9'};

My code works, but I keep getting compiler warnings:

non static data member initializers only available with C++11

and

extended initializer lists only available with C++11

I know that this isn't an issue because I'm compiling to C++11 standard, but I'm curious as to what is pre C++11 about my code.

I am hoping someone can give me some insight and suggest what I can do to make this code C++98 "friendly".

Also as requested, my compiler command:

> g++ -o test main.cpp

解决方案

To make it C++98 compatible, you need to initialize non-static class constants outside of the class declaration.

这篇关于C ++数组的初始化警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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