How to deal with noexcept in Visual Studio

前端 未结 11 1727
一整个雨季
一整个雨季 2021-01-31 07:42

I\'m trying to create a custom exception that derives from std::exception and overrides what(). At first, I wrote it like this:

class U         


        
11条回答
  •  北荒
    北荒 (楼主)
    2021-01-31 08:23

    Use a macro

    #ifndef _MSC_VER
    #define NOEXCEPT noexcept
    #else
    #define NOEXCEPT
    #endif
    

    And then define the function as

    virtual const char* what() const NOEXCEPT override
    

    You could also modify that to allow noexcept on later versions of VS by checking the value of _MSC_VER; for VS2012 the value is 1600.

提交回复
热议问题