相关疑难解决方法(0)

初始化时真的需要大括号吗?

根据GCC 4.6.3(Ubuntu/Linaro 4.6.3-1ubuntu5),我在以下代码中的数组初始化中缺少大括号:

#include <iostream>
#include <boost/array.hpp>
#include <array>

int main(){
  int                   plain[]   = {1,2,3,4,5};
  std::array  <int, 5>  std_arr   = {1,2,3,4,5}; // warning, see below
  boost::array<int, 5>  boost_arr = {1,2,3,4,5}; // warning, see below
  std::cout << plain[0] << std_arr[1] << boost_arr[2] << std::endl;
}
Run Code Online (Sandbox Code Playgroud)
> g++ test.cc -Wall -Wextra -pedantic --std=c++0x                                                                                  
test.cc: in function »int main()«:
test.cc:7:47: warning: curly braces missing around initialization for »std::array::value_type [5] {aka int [5]}« [-Wmissing-braces]
test.cc:8:47: warning: curly braces missing around initialization for »int [5]« [-Wmissing-braces] …

c++ gcc-warning

6
推荐指数
1
解决办法
1129
查看次数

标签 统计

c++ ×1

gcc-warning ×1