g ++警告声明多维,双数组 [英] g++ warning on declaring multidimensional, double array

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

问题描述

在我的C ++程序中,我试图初始化一个3 * 3 * 3类型double数组,所有的0。
在类头文件中,我声明了一个成员

  double list [3] [3] [3] 

当我打印出这个数组的内容时,我发现并不是所有的条目都是0, 。例如因此,我手动初始化这个数组到构造函数中的所有0:

$ b

$ list [1] [1] [1]的值为4.03158e-321


$ b <
$ b

  list = {{{0,0,0},{0,0,0},{0,0,0}},
{{0,0,0},{0,0,0},{0,0,0}},
{{0,0,0},{0,0,0},{0 ,0,0}}};

这使我的程序工作,但是,我得到编译器警告:

 警告:扩展初始化程序列表仅适用于-std = c ++ 0x或-std = gnu ++ 0x 



因此我的问题是


  1. 列表在
    头文件中初始化后是否有非零条目

  2. 为什么会收到上述警告消息,

我的编译器是g ++(Ubuntu / Linaro 4.5.2-8ubuntu4)4.5.2, 4.5.2(Ubuntu / Linaro 4.5.2-8ubuntu4)

解决方案

我错过了一些东西, p>

  class Class {
public:
double array [3] [3] [3];

Class():array(){}
};


In my C++ program I am trying to initialize a 3*3*3 array of type double with all 0's. In the class header file, I declared a member

double list[3][3][3];

When I printed out the content of this array, I found that not all entries are 0 as I expected. e.g. list[1][1][1] has value 4.03158e-321

Hence I manually initialized this array to all 0's in the constructor:

list = {{{0,0,0},{0,0,0},{0,0,0}},
      {{0,0,0},{0,0,0},{0,0,0}},
      {{0,0,0},{0,0,0},{0,0,0}}};

This makes my program work, however, I got the compiler warning:

warning: extended initializer lists only available with -std=c++0x or -std=gnu++0x

My question is therefore

  1. Why does list have non-zero entries after being initialized in the header?
  2. Why do I get the above warning message, and how to get rid of it?

My compiler is g++ (Ubuntu/Linaro 4.5.2-8ubuntu4) 4.5.2, with gcc version 4.5.2 (Ubuntu/Linaro 4.5.2-8ubuntu4)

解决方案

Am I missing something or can you not just do

class Class {
public:
    double array[3][3][3];

    Class() : array() { }
};

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

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