简体   繁体   English

将输入转换为类时C ++ Boost矩阵错误

[英]C++ Boost matrix error when transforming input to classes

First of all, I use boost library, and if it changes anything, the code is compiled on a Windows Machine. 首先,我使用boost库,如果更改了任何内容,则代码将在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. 好吧,我正在尝试将矩阵:{001 100 010}转换为:{1 3 2},但是奇怪的是我无法编译我的代码,也找不到错误,所以如果有人可以帮助我会很高兴我。 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. 提前致谢。

Near the end of the first error message is the text, "To disable this warning, use -D_SCL_SECURE_NO_WARNINGS". 第一条错误消息的结尾附近是文本“要禁用此警告,请使用-D_SCL_SECURE_NO_WARNINGS”。 https://msdn.microsoft.com/en-us/library/ttcz0bys.aspx has a more detailed discussion of warnings and checked iterators. https://msdn.microsoft.com/zh-cn/library/ttcz0bys.aspx对警告和已检查的迭代器进行了更详细的讨论。 In essence, Microsoft created "safe" mutations of Standard C++ functions to help developers avoid invalid iterator usage. 本质上,Microsoft创建了标准C ++函数的“安全”突变,以帮助开发人员避免无效的迭代器使用。 The error message suggests that you define _SCL_SECURE_NO_WARNINGS. 错误消息提示您定义_SCL_SECURE_NO_WARNINGS。 This can be done in the project properties C/C++/Preprocessor/Preprocessor Definitions. 这可以在项目属性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. 您可能有兴趣阅读上面的Microsoft页面,以获取有关选中的迭代器主题的更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM