1.在文件1中定义了基类:#ifndef __MY_BASE_HPP__
#define __MY_BASE_HPP__namespace MyDll
{
class MyBase
{
public:
virtual ~MyBase() {};
virtual void Print() = 0;protected:
MyBase() {};
}; //class MyBase
}; //namespace MyDll#endif //#ifndef __MY_BASE_HPP__在文件2中定义并导出了派生类:
#ifndef __MY_DERIVE_HPP__
#define __MY_DERIVE_HPP__#include <string>
#include "MyBase.hpp"using namespace std;namespace MyDll
{
class __declspec(dllexport) MyDerive : public MyBase
{
public:
MyDerive(const string &sText);
virtual ~MyDerive();
virtual void Print();private:
string _sText;
MyDerive();
}; //class MyDerive
}; //namespace MyDll#endif //#ifndef __MY_DERIVE_HPP__编译会得到如下警告信息:
1.
warning C4275: non dll-interface class 'MyDll::MyBase' used as base for dll-interface class 'MyDll::MyDerive' mybase.hpp(7) : see declaration of 'MyBase'
2.
warning C4251: '_sText' : class 'std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' needs to have dll-interface to be used by clients of class 'MyDll::MyDerive'但是如果将文件1和文件2合并成一个文件,或者将class Base也导出,就不会有问题,请问该怎么消除这些警告信息,即导出带基类的C++类,但是不导出基类??
#define __MY_BASE_HPP__namespace MyDll
{
class MyBase
{
public:
virtual ~MyBase() {};
virtual void Print() = 0;protected:
MyBase() {};
}; //class MyBase
}; //namespace MyDll#endif //#ifndef __MY_BASE_HPP__在文件2中定义并导出了派生类:
#ifndef __MY_DERIVE_HPP__
#define __MY_DERIVE_HPP__#include <string>
#include "MyBase.hpp"using namespace std;namespace MyDll
{
class __declspec(dllexport) MyDerive : public MyBase
{
public:
MyDerive(const string &sText);
virtual ~MyDerive();
virtual void Print();private:
string _sText;
MyDerive();
}; //class MyDerive
}; //namespace MyDll#endif //#ifndef __MY_DERIVE_HPP__编译会得到如下警告信息:
1.
warning C4275: non dll-interface class 'MyDll::MyBase' used as base for dll-interface class 'MyDll::MyDerive' mybase.hpp(7) : see declaration of 'MyBase'
2.
warning C4251: '_sText' : class 'std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' needs to have dll-interface to be used by clients of class 'MyDll::MyDerive'但是如果将文件1和文件2合并成一个文件,或者将class Base也导出,就不会有问题,请问该怎么消除这些警告信息,即导出带基类的C++类,但是不导出基类??
解决方案 »
- CHttpFile SendRequest 会抛出什么类型的异常?
- 菜鸟问题:如何根据menu的ID获得HMENU
- 求解: 非阻塞模式socket的问题
- 请问我这个情况如何解决?关于聊天室的制作,我是初学者,请多帮忙!!
- 我在做钩子时要用一个结构KBDLLHOOKSTRUCT,可是不知为什么老是说没有先定义?请帮帮忙!万分感谢!
- 直线 保存
- 分层窗口,裁剪圆形,有锯齿问题。
- ◆->谁买了和看了《程序员大本营》,怎么样?内容充实吗?水分多吗?
- 奇怪!:这样释放内存块为什么不行?
- 我们公司要做一块游戏,类似石器时代,想用java做服务器,但我怕速度有问题,没有c快,给位大虾给点意见,用java.c.c++那种比较好,那种速度快!!
- 如何注册自己写的拷贝钩子?
- 现在想学C++,哪种好些,版本最新的是?
namespace MyDll
{ MyDerive::MyDerive(const string &sText){}
MyDerive::~MyDerive(){}
void MyDerive::Print(){}
MyDerive::MyDerive(){}
}