c++(构造函数)LNK 2019错误

c++ (constructor) LNK 2019 error

本文关键字:2019 错误 LNK 构造函数 c++      更新时间:2023-10-16

可能的重复:
什么是未定义的引用/未解决的外部符号错误,如何修复?

我有一个LNK错误,它涉及一个类a及其派生类B。更准确地说,我有这个编译错误

Error   239 error LNK2019: unresolved external symbol "public: virtual __thiscall A::~A(void)" (??1A@@UAE@XZ) referenced in function "public: virtual __thiscall B::~B(void)" (??1B@@UAE@XZ)    D:Productspathfile.lib(B.obj)
Error   240 error LNK2019: unresolved external symbol "public: __thiscall A::A(void)" (??A@@QAE@XZ) referenced in function "public: __thiscall B::B(void)" (??B@@QAE@XZ)    D:Productspathfile.lib(B.obj)
Error   241 error LNK2019: unresolved external symbol "public: void __thiscall A::function(float * *,float * *,float * *,float * *,int)" (?function@A@@QAEXPAPAM000H@Z) referenced in function "public: class SomeType* __thiscall B::function_bis(void)" (?function_bis@B@@QAEPAVSomeType@@XZ) D:Productspathfile.lib(B.obj)

我想这可能与继承构造函数的调用有关,或者与函数()或函数比斯()的某些调用中不尊重签名有关。然而,我找不到这样的错误。

你有一个可能的解决方法的提示吗?这是(简化的)A和B的代码。

B.cpp

B::B(void)
{
}
B::B(Type1* d1, Type1* d2, Type1* r):A()
{
D1= d1;
D2= d2;
R= r;
}

B::~B( void )
{
}
SomeType* B::function()
{
// do things
function_bis() ;
}

B.h

class B:
public A
{
public:
B(void) ;
B(Type1* , Type1* , Type1* );
virtual ~B(void);
SomeType* function() ;
private:
Type1* D1;
Type1* D2;
Type1* R;
};

A.cpp

using namespace std ;
A::A(void){}
A::~A(void){}
void A::function_bis(float** d, float** d2, float** d3, float** d4, int n)
{}

A.h

class A
{
public:
A(void);
virtual ~A(void);
void function_bis(float** , float** , float** , float** , int );
};

谢谢!

代码中的所有内容看起来都是合法的。

我的猜测是,你实际上没有编译A.cpp,或者不知何故,你没有在链接步骤中包括生成的对象文件(你错过了A.cpp中定义的A::A、A::~A和A::function_bis)