Kev*_*vin 5 c++ compiler-errors vector visual-studio-2010
我正在对一些家庭作业C++代码进行评分,而学生则使用非标准构造函数来处理向量向量:
vector<vector<double> > A(rows, cols);
Run Code Online (Sandbox Code Playgroud)
where rows和cols是无符号整数.我们在课堂上教它的方式是
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 2013的计算机上运行的,这就是区别
当您在命令行进行编译时,您没有使用 VS 2010。
这是我从 VS 2010 命令行编译得到的结果:
C:\so-test>cl /O2 /EHsc /Tp test.cpp
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.40219.01 for 80x86
Copyright (C) Microsoft Corporation. All rights reserved.
test.cpp
Microsoft (R) Incremental Linker Version 10.00.40219.01
Copyright (C) Microsoft Corporation. All rights reserved.
/out:test.exe
test.obj
Run Code Online (Sandbox Code Playgroud)
当我从 VS 2013 命令行编译时,我收到错误消息(我从 VS 2012 命令行收到类似但略有不同的消息)。
我建议您查看显示的版本号,以验证您在命令行中使用的 MSVC 编译器版本。
| 归档时间: |
|
| 查看次数: |
500 次 |
| 最近记录: |