There are a few options for you in this type of situation.
- Export it.
- Ignore it.
- In-line it.
It is important to bear in mind that the "correct" way to export class from a dll is to export the entire class, including bases and members. For this reason there are several techniques such as this one on CodeProject, that use an "interface" and appropriate factory to create the class (and matching destruction).
This is not too useful for you in this situation, trying to export std::runtime_error
is probably more effort and likely to introduce even bigger issues later on.
Taken from the Microsoft Connect site here (webarchive), the family of these errors are essentially noise;
I recommend avoiding this in the first place - putting STL types in your DLL's interface forces you to play by the STL's rules (specifically, you can't mix different major versions of VC, and your IDL settings must match). However, there is a workaround. C4251 is essentially noise and can be silenced...
Stephan T. Lavavej (one of the maintainer's of Micrsoft's C++ library).
So long as the compiler options are consistent through the project, just silencing this warning should be just fine.
The final option is to define the BaseException
class inline and not export it at all.
In my experience, the inline option landed up almost always being the easiest for exception classes.
Changes in the C++ runtime for VS2015, have resulted in changes to the exporting of std::exception
(It is not exported from the runtime).
The inline option now seems to be the most appropriate at this time (your mileage may vary).
class Exception : exception {
public:
char const* what() const override;
};
inline char const* Exception::what() const {
/*...*/
};
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…