派生类C ++的DLL

时间:2016-11-23 11:11:43

标签: c++ dll

我有一个基类如下:

class Base
  {
  public:
    BASE_API     void * operator new(size_t, void * i_p) {return i_p;};
    BASE_API     void increase() {current_id++;};
    BASE_API     virtual ~Base(){};

#pragma warning(suppress: 4251)
    static thread_local int current_id;
  }
 thread_local int current_id;

在另一个库中我使用派生类:

class BASE_API Derived : public Base
  {
  public:
    BASE_API     void decrease() {Base::current_id--;};
    BASE_API     ~Derived(){};
  }

我没有写类BASE_API Base 的原因是具有线程存储持续时间的成员可能没有DLL接口。所以,我把BASE_API放在除了thread_local成员变量之外的每个类的成员之前。

现在我收到以下错误:

error C2220: warning treated as error - no 'object' file generated (compiling source file D:\****.cpp)
D:\****\Derived.h(37): warning C4275: non dll-interface class 'Base' used as base for dll-interface class 'Derived' (compiling source file D:\_****.cpp)

除了以下解决方案之外,还有其他方法可以摆脱错误

#pragma warning (push)
#pragma warning (disable:4275)
class BASE_API Derived : public Base
  {
  public:
    BASE_API     void decrease() {Base::current_id--;};
    BASE_API     ~Derived(){};
  }
#pragma warning (pop)

0 个答案:

没有答案