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

时间:2018-06-29 09:00:53

标签: c++ visual-studio visual-c++ dll lnk2019

在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   

问题可能出在哪里?

0 个答案:

没有答案