c++ - 由于动态链接库中的虚函数导致编译错误
问题描述
在 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
问题出在哪里?
解决方案
推荐阅读
- node.js - 如何处理 React Spa 上的刷新令牌?
- python-3.x - 在python中动态创建数据框
- .net - VSTO Outlook 插件:MeasureString 计算错误的宽度
- django - 在我的 Django 应用程序中设置搜索功能
- python - 如何仅读取 msg 文件的第一个电子邮件正文,不包括附加到该 msg 文件的邮件
- c++ - 使用 fltk 时文本未出现在编译窗口中
- typescript - ngrx 效果 - 结合两个 API
- racket - 创建一个函数以将向量向量转换为列表列表
- java - 在 Java 中使用 DAO 的列表列表
- python - 如何在python中使用beautifulsoup提取href内容