2015-05-27 42 views
0

我使用odeint boost來求解微分方程。在Visual Studio 2010中,也顯示出來沒有錯誤,但是當我使用Visual Studio 2013,我得到這個錯誤錯誤C4996:'std :: _ Copy_impl':禁用它是否安全?

xutility(2132): error C4996: 'std::_Copy_impl': 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'

我已經通過禁止使用這種#pragma warning(disable : 4996)odeint提供的樣本警告解決的問題現在正在工作。這是樣本,

#pragma warning(disable : 4996) 
#include <iostream> 
#include <boost/array.hpp> 
#include <boost/numeric/odeint.hpp> 

using namespace std; 
using namespace boost::numeric::odeint; 

const double sigma = 10.0; 
const double R = 28.0; 
const double b = 8.0/3.0; 

typedef boost::array< double, 3 > state_type; 

void lorenz(const state_type &x, state_type &dxdt, double t) 
{ 
    dxdt[0] = sigma * (x[1] - x[0]); 
    dxdt[1] = R * x[0] - x[1] - x[0] * x[2]; 
    dxdt[2] = -b * x[2] + x[0] * x[1]; 
} 

void write_lorenz(const state_type &x, const double t) 
{ 
    cout << t << '\t' << x[0] << '\t' << x[1] << '\t' << x[2] << endl; 
} 

int main(int argc, char **argv) 
{ 
    state_type x = { 10.0, 1.0, 1.0 }; // initial conditions 
    integrate(lorenz, x, 0.0, 25.0, 0.1, write_lorenz); 
} 

我的問題是可以安全地禁用此警告?謝謝

回答

1

代碼應該是安全的。我們在odeint的單元測試中禁用了相同的警告。

+4

_「我們禁用了相同的警告」_並不會引起我爲什麼它是安全的非常有說服力的論點。 – sehe

+1

:)對,它不能解釋爲什麼你可以禁用它。其實我不記得4996的問題是什麼。 – headmyshoulder

+1

鏈接的副本:) – sehe