2017-10-10 74 views
0

首先,我使用boost库,如果它改变了任何内容,代码将在Windows机器上编译。 代码本身包含更多的函数作用于矩阵,但只有这一个触发错误。 嗯,我想喜欢变换矩阵: {001 010} 喜欢的东西: {1 2} 但奇怪的是,我不能编译我的代码,我找不到错误所以如果有人能帮助我,我会很高兴。 代码如下:C++将输入转换为类时的Boost矩阵错误

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 ========== 

试图定位错误使我上面的功能。 在此先感谢。

回答

1

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

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