通过值返回boost ublas矩阵,仅在vs2012的发布配置中工作
returning a boost ublas matrix by value working only in release config for vs2012
我正在使用visual studio 2012,我在我的代码中隔离了一个问题,但我无法解决它。当在发布模式下运行它时,它工作完美,但如果我在调试模式下运行它,我会得到一个错误。代码是:
#include "stdafx.h"
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/io.hpp>
typedef boost::numeric::ublas::matrix<double> BMT;
BMT fun()
{
BMT mym;
mym.resize(3,3);
for(int i = 0; i<9;++i) mym(i/3,i%3)=i;
std::cout << mym << std::endl;
return mym;
}
int main(int argc, char* argv[])
{
fun();
//closing message
std::cout<<std::endl<<"press enter to exit."<<std::endl;
std::cin.ignore( std::numeric_limits<std::streamsize>::max(), 'n' );
}
,调试时的错误如下:
1>------ Build started: Project: myproject, Configuration: Debug x64 ------
1> myapp.cpp
1>C:Program Files (x86)Microsoft Visual Studio 11.0VCincludexmemory(348): error C4996: 'std::_Uninitialized_copy0': Function call with parameters that may be unsafe - this call relies on the caller to check that the passed values are correct. To disable this warning, use -D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual C++ 'Checked Iterators'
1> C:Program Files (x86)Microsoft Visual Studio 11.0VCincludexmemory(333) : see declaration of 'std::_Uninitialized_copy0'
1> C:thirdpartyvs2012x64boost_1_53_0boost/numeric/ublas/storage.hpp(94) : see reference to function template instantiation '_FwdIt std::uninitialized_copy<const double*,double*>(_InIt,_InIt,_FwdIt)' being compiled
1> with
1> [
1> _FwdIt=double *,
1> _InIt=const double *
1> ]
1> C:thirdpartyvs2012x64boost_1_53_0boost/numeric/ublas/storage.hpp(89) : while compiling class template member function 'boost::numeric::ublas::unbounded_array<T>::unbounded_array(const boost::numeric::ublas::unbounded_array<T> &)'
1> with
1> [
1> T=double
1> ]
1> C:thirdpartyvs2012x64boost_1_53_0boost/numeric/ublas/matrix.hpp(160) : see reference to function template instantiation 'boost::numeric::ublas::unbounded_array<T>::unbounded_array(const boost::numeric::ublas::unbounded_array<T> &)' being compiled
1> with
1> [
1> T=double
1> ]
1> C:thirdpartyvs2012x64boost_1_53_0boost/numeric/ublas/matrix.hpp(100) : see reference to class template instantiation 'boost::numeric::ublas::unbounded_array<T>' being compiled
1> with
1> [
1> T=double
1> ]
1> junkApp1.cpp(10) : see reference to class template instantiation 'boost::numeric::ublas::matrix<T>' being compiled
1> with
1> [
1> T=double
1> ]
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
你知道是什么问题吗?
我在使用ublas时遇到了类似的问题。我不确定原因可能是什么,但我想这与ublas的写时复制/按需复制优化有关。它是一个选项,只是使用定义-D_SCL_SECURE_NO_WARNINGS和完成它?我有一个全局设置,因为我认为90%的警告是OS特定的BS。
问题是您正在编译中将警告视为错误。
编辑:Microsoft已经决定c++(和C)的某些部分被弃用,并且编译器将这些部分的使用报告为错误,除非定义了_SCL_SECURE_NO_WARNINGS(分别为_CRT_SECURE_NO_WARNINGS)。
相关文章:
- 为不同配置设置MSVC_RUNTIME_LIBRARY的正确方法是什么
- 无法找到/读取配置文件.conf-FileIOException
- 在WSL:configure_file上对config_file的每次调用都失败:配置文件时出现问题
- 一种在C++中读取TXT配置文件的简单方法
- 生成MRPT库时cmake配置失败
- FFMPEG配置文件级别id大小无效
- 如何通过Conan和CMake找到用于pkg配置的.pc文件
- 配置文件解析器仅返回以前的值
- 我的程序有一个保存配置文件的GUI,如何双击此配置文件以直接加载带有配置数据的GUI?
- 更改命令行 qt5 源代码构建配置的正确/快速方法
- 是否可以配置提升日志刷新?
- 如何配置Visual Studio Code以使用cygwin,cmake和gcc进行调试
- C/C++:打印(配置)头文件的内容
- 配置:错误:找不到 MySQL 包含目录
- 安装 psutil 和为 pypy 配置期间出错
- 叮当格式化程序多行格式配置错误
- 使用 Eclipse CDT 进行 Cplex 配置
- 为c++配置Visual studio代码
- 如何定义自定义生成配置类型,其中通常是.exe的目标改为 DLL
- 我可以同时使用属性文件和运行时配置配置log4cxx吗?