将输入转换为类时,C ++ Boost矩阵错误(C++ Boost matrix error when transforming input to classes)

编程入门 行业动态 更新时间:2024-10-26 04:29:43
将输入转换为类时,C ++ Boost矩阵错误(C++ Boost matrix error when transforming input to classes)

首先,我使用boost库,如果它改变了什么,代码将在Windows机器上编译。 代码本身包含更多的函数作用于矩阵,但只有这一个触发了错误。 好吧,我正在尝试转换矩阵,如:{001 100 010}类似于:{1 3 2}但奇怪的是我无法编译我的代码,我找不到错误,所以如果有人能帮助我会很高兴我。 代码下方:

using namespace boost::numeric::ublas; typedef matrix <float, row_major, unbounded_array<float>> MATRIXf; MATRIXf matrix_to_class (const MATRIXf inputM) { MATRIXf output; for (std::size_t line = 0; line < inputM.size1(); line++) { for (std::size_t column = 0; column < inputM.size2(); column++) { if (column == 1) { output.insert_element(line,0.0,column); } } } return output; }

这是错误代码:

1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\xutility(2372): error C4996: 'std::copy::_Unchecked_iterators::_Deprecate': Call to 'std::copy' 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 14.0\vc\include\xutility(2372): note: see declaration of 'std::copy::_Unchecked_iterators::_Deprecate' 1> e:\c++ libraries\general\boost_1_65_0\boost\numeric\ublas\storage.hpp(204): note: see reference to function template instantiation '_OutIt *std::copy<float*,float*>(_InIt,_InIt,_OutIt)' being compiled 1> with 1> [ 1> _OutIt=float *, 1> _InIt=float * 1> ] 1> e:\c++ libraries\general\boost_1_65_0\boost\numeric\ublas\storage.hpp(201): note: while compiling class template member function 'boost::numeric::ublas::unbounded_array<float,std::allocator<T>> &boost::numeric::ublas::unbounded_array<T,std::allocator<T>>::operator =(const boost::numeric::ublas::unbounded_array<T,std::allocator<T>> &)' 1> with 1> [ 1> T=float 1> ] 1> e:\c++ libraries\general\boost_1_65_0\boost\numeric\ublas\matrix.hpp(310): note: see reference to function template instantiation 'boost::numeric::ublas::unbounded_array<float,std::allocator<T>> &boost::numeric::ublas::unbounded_array<T,std::allocator<T>>::operator =(const boost::numeric::ublas::unbounded_array<T,std::allocator<T>> &)' being compiled 1> with 1> [ 1> T=float 1> ] 1> e:\c++ libraries\general\boost_1_65_0\boost\numeric\ublas\matrix.hpp(102): note: see reference to class template instantiation 'boost::numeric::ublas::unbounded_array<float,std::allocator<T>>' being compiled 1> with 1> [ 1> T=float 1> ] 1> g:\c++ python\travail\visualstudio\visualstudio\guigui\neural net\neural net\utils.hpp(21): note: see reference to class template instantiation 'boost::numeric::ublas::matrix<float,boost::numeric::ublas::row_major,boost::numeric::ublas::unbounded_array<float,std::allocator<T>>>' being compiled 1> with 1> [ 1> T=float 1> ] 1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\xmemory(102): error C4996: 'std::uninitialized_copy::_Unchecked_iterators::_Deprecate': Call to 'std::uninitialized_copy' 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 14.0\vc\include\xmemory(102): note: see declaration of 'std::uninitialized_copy::_Unchecked_iterators::_Deprecate' 1> e:\c++ libraries\general\boost_1_65_0\boost\numeric\ublas\storage.hpp(94): note: see reference to function template instantiation '_FwdIt *std::uninitialized_copy<const float*,float*>(_InIt,_InIt,_FwdIt)' being compiled 1> with 1> [ 1> _FwdIt=float *, 1> _InIt=const float * 1> ] 1> e:\c++ libraries\general\boost_1_65_0\boost\numeric\ublas\storage.hpp(89): note: while compiling class template member function 'boost::numeric::ublas::unbounded_array<float,std::allocator<T>>::unbounded_array(const boost::numeric::ublas::unbounded_array<T,std::allocator<T>> &)' 1> with 1> [ 1> T=float 1> ] 1> e:\c++ libraries\general\boost_1_65_0\boost\numeric\ublas\matrix.hpp(162): note: see reference to function template instantiation 'boost::numeric::ublas::unbounded_array<float,std::allocator<T>>::unbounded_array(const boost::numeric::ublas::unbounded_array<T,std::allocator<T>> &)' being compiled 1> with 1> [ 1> T=float 1> ] ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

试图找到错误让我进入上面的功能。 提前致谢。

First of all, I use boost library, and if it changes anything, the code is compiled on a Windows Machine. The code itself contains a lot more of function acting upon matrices but only this one triggers the error. Well, I am trying to transform matrix like : {001 100 010} To something like : {1 3 2} But strangely I can't compile my code and I can't find the error so I would be glad if anyone could help me. Below the code :

using namespace boost::numeric::ublas; typedef matrix <float, row_major, unbounded_array<float>> MATRIXf; MATRIXf matrix_to_class (const MATRIXf inputM) { MATRIXf output; for (std::size_t line = 0; line < inputM.size1(); line++) { for (std::size_t column = 0; column < inputM.size2(); column++) { if (column == 1) { output.insert_element(line,0.0,column); } } } return output; }

Here is the error code:

1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\xutility(2372): error C4996: 'std::copy::_Unchecked_iterators::_Deprecate': Call to 'std::copy' 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 14.0\vc\include\xutility(2372): note: see declaration of 'std::copy::_Unchecked_iterators::_Deprecate' 1> e:\c++ libraries\general\boost_1_65_0\boost\numeric\ublas\storage.hpp(204): note: see reference to function template instantiation '_OutIt *std::copy<float*,float*>(_InIt,_InIt,_OutIt)' being compiled 1> with 1> [ 1> _OutIt=float *, 1> _InIt=float * 1> ] 1> e:\c++ libraries\general\boost_1_65_0\boost\numeric\ublas\storage.hpp(201): note: while compiling class template member function 'boost::numeric::ublas::unbounded_array<float,std::allocator<T>> &boost::numeric::ublas::unbounded_array<T,std::allocator<T>>::operator =(const boost::numeric::ublas::unbounded_array<T,std::allocator<T>> &)' 1> with 1> [ 1> T=float 1> ] 1> e:\c++ libraries\general\boost_1_65_0\boost\numeric\ublas\matrix.hpp(310): note: see reference to function template instantiation 'boost::numeric::ublas::unbounded_array<float,std::allocator<T>> &boost::numeric::ublas::unbounded_array<T,std::allocator<T>>::operator =(const boost::numeric::ublas::unbounded_array<T,std::allocator<T>> &)' being compiled 1> with 1> [ 1> T=float 1> ] 1> e:\c++ libraries\general\boost_1_65_0\boost\numeric\ublas\matrix.hpp(102): note: see reference to class template instantiation 'boost::numeric::ublas::unbounded_array<float,std::allocator<T>>' being compiled 1> with 1> [ 1> T=float 1> ] 1> g:\c++ python\travail\visualstudio\visualstudio\guigui\neural net\neural net\utils.hpp(21): note: see reference to class template instantiation 'boost::numeric::ublas::matrix<float,boost::numeric::ublas::row_major,boost::numeric::ublas::unbounded_array<float,std::allocator<T>>>' being compiled 1> with 1> [ 1> T=float 1> ] 1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\xmemory(102): error C4996: 'std::uninitialized_copy::_Unchecked_iterators::_Deprecate': Call to 'std::uninitialized_copy' 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 14.0\vc\include\xmemory(102): note: see declaration of 'std::uninitialized_copy::_Unchecked_iterators::_Deprecate' 1> e:\c++ libraries\general\boost_1_65_0\boost\numeric\ublas\storage.hpp(94): note: see reference to function template instantiation '_FwdIt *std::uninitialized_copy<const float*,float*>(_InIt,_InIt,_FwdIt)' being compiled 1> with 1> [ 1> _FwdIt=float *, 1> _InIt=const float * 1> ] 1> e:\c++ libraries\general\boost_1_65_0\boost\numeric\ublas\storage.hpp(89): note: while compiling class template member function 'boost::numeric::ublas::unbounded_array<float,std::allocator<T>>::unbounded_array(const boost::numeric::ublas::unbounded_array<T,std::allocator<T>> &)' 1> with 1> [ 1> T=float 1> ] 1> e:\c++ libraries\general\boost_1_65_0\boost\numeric\ublas\matrix.hpp(162): note: see reference to function template instantiation 'boost::numeric::ublas::unbounded_array<float,std::allocator<T>>::unbounded_array(const boost::numeric::ublas::unbounded_array<T,std::allocator<T>> &)' being compiled 1> with 1> [ 1> T=float 1> ] ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Trying to locate the error brings me to the function above. Thanks in advance.

最满意答案

在第一条错误消息的末尾附近是文本“要禁用此警告,请使用-D_SCL_SECURE_NO_WARNINGS”。 https://msdn.microsoft.com/en-us/library/ttcz0bys.aspx对警告和检查迭代器进行了更详细的讨论。 从本质上讲,Microsoft创建了标准C ++函数的“安全”突变,以帮助开发人员避免使用无效的迭代器。 该错误消息表明您定义了_SCL_SECURE_NO_WARNINGS。 这可以在项目属性C / C ++ /预处理器/预处理器定义中完成。 在我过去工作的一个项目中,由于性能受到影响,我们禁用了所有“安全”版本的功能。

您可能有兴趣阅读上面的Microsoft页面,以获取有关已检查迭代器主题的更多信息。

Near the end of the first error message is the text, "To disable this warning, use -D_SCL_SECURE_NO_WARNINGS". https://msdn.microsoft.com/en-us/library/ttcz0bys.aspx has a more detailed discussion of warnings and checked iterators. In essence, Microsoft created "safe" mutations of Standard C++ functions to help developers avoid invalid iterator usage. The error message suggests that you define _SCL_SECURE_NO_WARNINGS. This can be done in the project properties C/C++/Preprocessor/Preprocessor Definitions. In a project I worked on in the past, we disabled all the "safe" versions of the functions because of the performance hit.

You may be interested in reading the above Microsoft page for more information about the checked iterator topic.

更多推荐

本文发布于:2023-08-04 08:36:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1412611.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:矩阵   转换为   错误   Boost   matrix

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!