小编Kev*_*vin的帖子

了解Visual Studio 2010中的编译器选项差异和严格的C++合规性

我正在对一些家庭作业C++代码进行评分,而学生则使用非标准构造函数来处理向量向量:

vector<vector<double> > A(rows, cols);
Run Code Online (Sandbox Code Playgroud)

where rowscols是无符号整数.我们在课堂上教它的方式是

vector<vector<double> > A(rows, vector<double>(cols));
Run Code Online (Sandbox Code Playgroud)

填充构造函数之后(http://www.cplusplus.com/reference/vector/vector/vector/中的 2 )

我正在使用批处理文件使用命令行编译所有学生代码

cl /O2 /EHsc /Tp <filename>
Run Code Online (Sandbox Code Playgroud)

并且这个命令在上面提到的学生行中引发了这个错误:

error C2664: 'std::vector<std::vector<double,std::allocator<_Ty>>,std::allocator<std::vector<_Ty,std::allocator<_Ty>>>>::vector(std::initializer_list<std::vector<_Ty,std::allocator<_Ty>>>,const std::allocator<std::vector<_Ty,std::allocator<_Ty>>> &)' : cannot convert argument 2 from 'unsigned int' to 'const std::vector<double,std::allocator<_Ty>> &'
    with
    [
        _Ty=double
    ]
    Reason: cannot convert from 'unsigned int' to 'const std::vector<double,std::allocator<_Ty>>'
    with
    [
        _Ty=double
    ]
    Constructor for class 'std::vector<double,std::allocator<_Ty>>' is declared 'explicit'
    with
    [
        _Ty=double
    ]
Run Code Online (Sandbox Code Playgroud)

但是当我创建一个项目并使用默认参数MSVC 2010构建它时,它既不会抛出警告也不会抛出错误.

我试图了解哪些编译器选项负责允许它在IDE中没有警告的情况下通过,以及我将其关闭的内容.

我尝试在http://msdn.microsoft.com/en-us/library/2tb15w2z(v=vs.100).aspx中找到答案,但我无法回答.

编辑:我认为这可能对其他人有所帮助:感谢我现在理解的注释,IDE中调用的构造函数是范围构造函数(上面链接中的#3).

这是我的特殊问题:两种方法都使用相同的编译器和不同的选项(一种是IDE的默认选项,另一种是上面说明的选项).批处理文件抛出错误,IDE不会.我需要帮助确定IDE的命令行参数中要更改的内容,以便它抛出错误.

更新:我包含错误消息.

更新2:事实证明,脚本是在具有MSVC …

c++ compiler-errors vector visual-studio-2010

5
推荐指数
1
解决办法
500
查看次数

标签 统计

c++ ×1

compiler-errors ×1

vector ×1

visual-studio-2010 ×1