c++ - vs c++ dll - 标量删除析构函数

标签 c++ visual-studio dll

我在 visual studio c++ 中编程。我在 DLL 中有 Field、IField、Map 和 IMap。我创建接口(interface) IField 和 IMap 以在单元测试中访问 Field 和 Map。当我在单元测试中运行这个简单的代码时:

IMap m;
IField f(3, 4);
m.shoot(f);

我有以下错误:

LNK2019 unresolved external symbol "public: virtual __thiscall Field::~Field(void)" (??1Field@@UAE@XZ) referenced in function "public: virtual void * __thiscall Field::`scalar deleting destructor'(unsigned int)" (??_GField@@UAEPAXI@Z) TestShipGameDll

#pragma once
class Field
{
public:
    Field(int x, int y) : x(x), y(y) {}
    virtual ~Field() {}
protected:
    int x;
    int y;
};

.

#ifdef IFIELD_EXPORTS  
#define IFIELD_API __declspec(dllexport)   
#else  
#define IFIELD_API __declspec(dllimport)   
#endif  

class IField : 
    public Field 
{
public:
    IFIELD_API IField(int x, int y) :Field(x, y)
    IFIELD_API virtual ~IField() {}
};

.

class Map
{
public:
    Map();
    virtual ~Map();
    void shoot(Field field) 
    {
        //here is empty body of function
    }    

};

.

#ifdef IMAP_EXPORTS  
#define IMAP_API __declspec(dllexport)   
#else  
#define IMAP_API __declspec(dllimport)   
#endif  

class IMap :
    public Map
{
public:
    IMAP_API IMap() {}
    IMAP_API virtual ~IMap() {}
    IMAP_API void shoot(Field field)
    {
        Map::shoot(field);
    }
};

. 有点奇怪。看起来它缺少复制构造函数,但我在 Field 中没有任何指针。只有自动变量 x 和 y。您有解决这个奇怪错误的任何提示吗?

最佳答案

您必须使用 IFIELD_API 导出整个类 - 否则编译器生成的函数在共享库之外不可见,并且您将遇到链接器错误。

关于c++ - vs c++ dll - 标量删除析构函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42449063/

相关文章:

delphi - 在 Delphi 6 应用程序的运行时在两个版本的基于 ActiveX IDispatch 的相同界面之间切换?

c++ - 您的计算机缺少 api-ms-win-core-synch-l1-2-1.dll

c++ - 用作一维的多维 vector 的迭代器?

c++ - 无法 std::bind 成员函数

javascript - 调试时防止 Visual Studio 中的 .min.js 文件内自动出现 "step into"

c++ - 警告 C4180 : qualifier applied to function type has no meaning; ignored

c# - 如何修复 Microsoft Visual Studio 错误 : "package did not load correctly"?

c++ - 如何在 win32 DLL 程序中使用 IntelliProtector API

c++ - do-while-false 循环是否常见?

c++ - 使用 CListBox::GetTopIndex() 调试断言。想法?