How to deal with noexcept in Visual Studio

前端 未结 11 1706
一整个雨季
一整个雨季 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:24

    Add the following lines in your code in Visual Studio:

    #ifdef _NOEXCEPT
    #define noexcept _NOEXCEPT
    #endif
    
    0 讨论(0)
  • 2021-01-31 08:27

    The noexcept is one of the easiest "lacks" of MSVC to deal with: Just use the macro _NOEXCEPT which under MSVC2013 is defined in yvals.h .

    0 讨论(0)
  • 2021-01-31 08:28

    add the below path to the additional include directories

    C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include
    

    at this location there is file called "yvals.h" which contain definition of _NOEXCEPT

    0 讨论(0)
  • 2021-01-31 08:31

    It seems that the old throw() (deprecated in C++11) works in both compilers. So I changed the code to:

    virtual const char* what() const throw() override
    
    0 讨论(0)
  • 2021-01-31 08:41

    What I've recently used is following:

    #ifdef _MSC_VER
    #define NOEXCEPT _NOEXCEPT
    #else
    #define NOEXCEPT noexcept
    #endif
    

    and then just use NOEXCEPT everywhere.

    0 讨论(0)
提交回复
热议问题