[ACCEPTED]-C4275 warning in Visual Studio-visual-c++

Accepted answer
Score: 22

MSDN: http://msdn.microsoft.com/en-us/library/3tdb471s.aspx

"An exported class [as in DLL] was 8 derived from a class that was not exported 7 [as in DLL]."

Apparently you are declaring 6 MyException to be exportable from a DLL (by using: __declspec(dllexport)), while 5 std::runtime_error is not exportable. Consider if MyException really 4 needs to be exportable. However, if none 3 of the issues listed on the above page apply 2 to your specific case, then you can disregard 1 that warning--just be aware of the issues.

Score: 2

I wound up here looking for an answer to 17 the same problem. I had a custom exception 16 derived from std::runtime_error and was 15 exporting it from my dll.

For exceptions, it 14 seems like the simplest solution is to NOT 13 EXPORT the derived class. You can do this 12 if you move your implementation from the 11 source (.CPP) file into the header (.HPP). For 10 me, this was trivial. I imagine that in 9 most cases with exceptions this would be 8 the case.

This is a "good thing" because 7 the client actual compiles and links the 6 implementation of your custom exception 5 with their implementation of std::runtime_error. This 4 is what you want and is, in fact, what the 3 C4275 warning is trying to protect you from: a 2 runtime incompatibility between the two 1 std::runtime_exception object types.

More Related questions