由于动态链接库中的虚函数而导致编译错误

问题描述 投票:0回答:1

在MSVC dll项目中,我试图创建一个包含基类的dll

//header file
class MATHLIBRARY_API Shape {
protected:
    int width, height;
public:
    Shape(int, int);
    int area(void) { return -1; };
};

已成功编译,但是在向函数添加虚拟说明符时

class MATHLIBRARY_API Shape {
protected:
     int width, height;
public:
     Shape(int, int);
     virtual int area(void) { return -1; };
};

编译器显示错误消息

Error   LNK2019 unresolved external symbol `__declspec(dllimport) const Shape::`vftable'" (__imp_??_7Shape@@6B@) referenced in function "public: __thiscall Shape::Shape(int,int)" (??0Shape@@QAE@HH@Z) Dll3    c:\Users\langj\source\repos\Dll3\Dll3\Dll3.obj  1   

哪里可能出问题了?

c++ visual-studio visual-c++ dll lnk2019
1个回答
0
投票

未定义哪个库关键字。能否请您解释根本原因

© www.soinside.com 2019 - 2024. All rights reserved.