使用“本身”初始化矢量与MSVC2013一起使用,而不是使用GCC 4.8.1

时间:2014-05-04 19:06:50

标签: c++ gcc

以下代码使用GCC 4.8.1打印0(为什么不打),但使用MSVC2013打印10(为什么?):

#include <iostream>
#include <vector>

const int y = 10;

int main()
{
  std::vector<double> y(y);
  std::cout << y.size() << std::endl;

  return 0;
}

1 个答案:

答案 0 :(得分:0)

我认为你需要编译 视觉工作室中的warning level 4 or warning is an error
ggcc -Wall and -Werror or -Winit-self or -Wuninitialized 编译,但你有分配问题。

对我来说,最好的标志是: -std=c++11 -pipe -m64 -ansi -fPIC -g -O3 -fno-exceptions -fstack-protector -Wl,-z,relro -Wl,-z,now -fvisibility=hidden -W -Wall -Wno-unused-parameter -Wno-unused-function -Wno-unused-label -Wpointer-arith -Wformat -Wreturn-type -Wsign-compare -Wmultichar -Wformat-nonliteral -Winit-self -Wuninitialized -Wno-deprecated -Wformat-security -Werror