相关疑难解决方法(0)

如何dllexport从std :: runtime_error派生的类?

我已经设置了一个库,提供了一个从标准异常派生的异常类:

#include <stdexcept>
#include <string>

class BaseException : public std::runtime_error
{
    public:
        BaseException( std::string const & msg );
};
Run Code Online (Sandbox Code Playgroud)

到现在为止还挺好.在Unix上编译和处理得很好.现在我准备将其编译成Windows DLL:

#ifdef WIN32
#define MY_EXPORT __declspec(dllexport)
#else
#define MY_EXPORT
#endif

#include <stdexcept>
#include <string>

class MY_EXPORT BaseException : public std::runtime_error
{
    public:
        BaseException( std::string const & msg );
};
Run Code Online (Sandbox Code Playgroud)

但是,这给了我警告C4275 : non – DLL-interface class 'std::runtime_error' used as base for DLL-interface class 'BaseException'.

不幸的是,我对微软风格的文档有些过敏:过于冗长,而且不是很重要.它让我完全不知道对我解决问题的实际期望是什么.

你们有人可以开导我吗?我可以删除基类,但然后捕获std::runtime_errorstd::exception不会捕获我的自定义异常类,我非常希望这是可能的.所以...?

c++ windows dll exception dllexport

14
推荐指数
1
解决办法
3875
查看次数

标签 统计

c++ ×1

dll ×1

dllexport ×1

exception ×1

windows ×1