g ++警告声明多维,双数组 [英] g++ warning on declaring multidimensional, double array
问题描述
在我的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
因此我的问题是
- 列表在
头文件中初始化后是否有非零条目
- 为什么会收到上述警告消息,
我的编译器是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
- Why does list have non-zero entries after being initialized in the header?
- 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屋!