gpt4 book ai didi

c++ - 按值返回 boost ublas 矩阵仅在 vs2012 的发布配置中工作

转载 作者:太空狗 更新时间:2023-10-29 21:24:00 24 4
gpt4 key购买 nike

我正在使用 visual studio 2012,我在我的代码中发现了一个问题,但我无法解决它。在 Release模式下运行它时它工作完美,但如果我在 Debug模式下运行它会出现错误。代码是:

#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.0\VC\include\xmemory(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.0\VC\include\xmemory(333) : see declaration of 'std::_Uninitialized_copy0'
1> C:\thirdparty\vs2012\x64\boost_1_53_0\boost/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:\thirdparty\vs2012\x64\boost_1_53_0\boost/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:\thirdparty\vs2012\x64\boost_1_53_0\boost/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:\thirdparty\vs2012\x64\boost_1_53_0\boost/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% 的警告都是操作系统特定的废话。

关于c++ - 按值返回 boost ublas 矩阵仅在 vs2012 的发布配置中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17051631/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com