【问题标题】:error C4996: 'std::_Copy_impl': is it safe to disable it? [duplicate]错误 C4996:'std::_Copy_impl':禁用它是否安全? [复制]
【发布时间】:2015-05-27 00:22:43
【问题描述】:

我使用odeint boost 来求解微分方程。在 Visual Studio 2010 中,没有出现错误,但是当我使用 Visual Studio 2013 时,我得到了这个错误

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);
}

我的问题是禁用此警告是否安全?谢谢

【问题讨论】:

    标签: c++ visual-studio-2012 boost odeint


    【解决方案1】:

    代码应该是安全的。我们在 odeint 的单元测试中禁用了相同的警告。

    【讨论】:

    • “我们已禁用相同的警告” 并没有让我觉得这是一个非常有说服力的论据,为什么它是安全的。
    • :) 是的,它没有解释为什么你可以禁用它。其实我不记得4996有什么问题了。
    • 链接的副本确实:)
    猜你喜欢
    • 2013-10-05
    • 1970-01-01
    • 1970-01-01
    • 2016-07-24
    • 2011-05-05
    • 2015-03-28
    • 2013-06-24
    • 1970-01-01
    • 2012-11-13
    相关资源
    最近更新 更多