错误"E2285 找不到匹配..."升级到 RAD11 后缺少代码中的构造函数



我的雇主正在考虑升级到RAD11,所以我必须测试它是否适合我们的需求,所以我正在将我的一个项目(巨大的win32 CAD/CAM应用程序)从BDS2006移植到RAD11(试用版28.0.44500.8973),并解决了大多数问题(与VCL和WinAPI接口相关的变化有关Unicode),但有了这个错误,我撞上了墙…

对于某些类和结构(不是全部),有时(仅在某些行而不是全部)编译器会抱怨缺少构造函数,这些构造函数总是存在于这样的代码中(参见标记为// ***的注释):

//---------------------------------------------------------------------------
//--- Crypto ver: 1.24 ------------------------------------------------------
//---------------------------------------------------------------------------
#ifndef _crypto_h
#define _crypto_h
//---------------------------------------------------------------------------
#define _mod_type DWORD
//---------------------------------------------------------------------------
struct _mod_type2
{
_mod_type h,l;  // (high,low) or (integer,fractional)
_mod_type2()                { h=0; l=0; }
_mod_type2(_mod_type2& a)   { *this=a; }    // *** this is the "missing" constructor
~_mod_type2()               {};
_mod_type2* operator = (const _mod_type2 *a) { *this=a; return this; }
//_mod_type2* operator = (const _mod_type2 &a) { ...copy...; return this; }
_mod_type2(int        a)    { h=a; l=0; }
_mod_type2(_mod_type& a)    { h=a; l=0; }
_mod_type2 operator = (int        a)    { h=a; l=0; return *this; }
_mod_type2 operator = (_mod_type& a)    { h=a; l=0; return *this; }
int operator == (_mod_type2 a) { return (h==a.h)&&(l==a.l); }
int operator != (_mod_type2 a) { return (h!=a.h)||(l!=a.l); }
int operator >= (_mod_type2 a) { if (h!=a.h) return (h>a.h); return (l>=a.l); }
int operator >  (_mod_type2 a) { if (h!=a.h) return (h>a.h); return (l> a.l); }
int operator <= (_mod_type2 a) { if (h!=a.h) return (h<a.h); return (l<=a.l); }
int operator <  (_mod_type2 a) { if (h!=a.h) return (h<a.h); return (l< a.l); }
};
//---------------------------------------------------------------------------
bool error(_mod_type2 a,_mod_type2 b)
{
bool x;
x = (_mod_type2(a)>=_mod_type2(b));     // *** this line produce error
/*
[bcc32 Error] crypto.h(34): E2285 Could not find a match for '_mod_type2::_mod_type2(_mod_type2&)'
Full parser context
win_main.cpp(5): #include crypto.h
crypto.h(32): parsing: bool error(_mod_type2,_mod_type2)
*/
return x;
}
//---------------------------------------------------------------------------
#endif
//---------------------------------------------------------------------------

总是这样的构造函数:

class_name(class_name& a)   { *this=a; }

由于BDS2006中的编译器错误,我在所有的结构和类中都有

如果我注释掉构造函数(所以c++将使用默认的构造函数),错误通常会消失,但不是所有的类/结构…

上面的简单代码产生错误(只需#包含它到使用的空c++ win32 Form App项目经典编译器)) .

所以问题是:

Q1我的代码有什么问题吗?

Q2如何解决这个问题?

使用新的编译器似乎没有问题,但这不是一个选择,因为整个项目不是为它编写的,移植它将是一个巨大的努力,需要太长时间(遇到更多这样的墙壁,没有试用版的工作RAD帮助,这在这一点上通常不是一个好主意)…

PS所有的qa在这里处理这个错误我发现是由于真的缺少构造函数,这不是我的情况…

看来我找到解决办法了。我只需要改变所有类型为:

的构造函数
T(T& a)

T(const T& a)

其中T为结构或类名…

在我的项目中改变了所有的构造器后,我得到了0编译器错误,我只剩下了一个链接器错误,这是另一天的战斗。

最新更新