gpt4 book ai didi

c++ - 将一小段代码从 c++11 转换为 c++03?

转载 作者:太空宇宙 更新时间:2023-11-04 15:17:45 25 4
gpt4 key购买 nike

我是一名试图编译 C++ 代码的社会科学家,遇到了一些小问题,我认为如果你了解 C++ 就很容易解决,但对我来说却难以理解。

尝试在 V2008 上编译,但我的代码似乎使用了一些 C++11 语法技巧。

In principle, I think this is solution ,但我真的不懂 C++,所以不确定如何实现。

代码块:

Optimiser::Optimiser(double eps, double delta, unsigned long max_itr, long random_order)
{
this->eps = eps;
this->delta = delta;
this->max_itr = max_itr;
this->random_order = random_order;
}

Optimiser::Optimiser() : Optimiser::Optimiser(1e-5, 1e-2, 1000, 1)
{
//ctor
}

我得到的错误(引用 Optimiser::Optimiser() : Optimiser::Optimiser(1e-5, 1e-2, 1000,1) 行)是:

c:\Program Files (x86)\Common Files\Microsoft\Visual C++ for Python\9.0\VC\Include\xlocale(342) : warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc
src\Optimiser.cpp(39) : error C2039: '{ctor}' : is not a member of 'Optimiser' include\Optimiser.h(26) : see declaration of 'Optimiser'
src\Optimiser.cpp(40) : error C2614: 'Optimiser' : illegal member initialization: 'Optimiser' is not a base or member
error: command '"c:\Program Files (x86)\Common Files\Microsoft\Visual C++ for Python\9.0\VC\Bin\amd64\cl.exe"' failed with exit status 2

最佳答案

直到 C++11 才允许委托(delegate)构造函数。也就是说,您将复制代码,但您可以简单地将第二个构造函数更改为

Optimiser::Optimiser()
{
eps = 1.0e-5;
delta = 1.0e-2;
max_itr = 1000UL;
random_order = 1L;
//rest of your ctor
}

关于c++ - 将一小段代码从 c++11 转换为 c++03?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28130048/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com