代码之家  ›  专栏  ›  技术社区  ›  liaK

如何摆脱“C++异常规范被忽略”的警告

  •  7
  • liaK  · 技术社区  · 15 年前

    void func1() throw (CCustomException);
    

    忽略C++异常规范 _declspec(无)

    MSDN - Documentation 但我不明白。另外,我不想仅仅因为警告出现就禁用它。我想知道我做错了什么而不是让它失效。

    myfunc() 访问那个 func1() dll中没有异常规范列表。因此,我也尝试在函数中使用相应的异常规范列表,

    void myfunc1() throw (CCustomException);
    

    但我还是得到了警告。这个警告是关于什么的?如何消除它?我在WindowsXP中使用Qt4.5。

    3 回复  |  直到 15 年前
        1
  •  11
  •   Alexandre C.    15 年前

    好吧,这不是答案,但我会的 throw away the exception specification and never use it again .

    #ifdef _MSC_VER 
    #pragma warning(push)
    #pragma warning(disable:xxxx)
    #endif 
    
    ...
    
    #ifdef _MSC_VER 
    #pragma warning(pop)
    #endif
    

    编辑:禁用警告是完全安全的。异常规范是有害的,编译器只是告诉您它正在为您禁用它们。即使它违反了标准。

        2
  •  0
  •   el.pescado - нет войне    15 年前

    您可以尝试使用预处理器:

    #ifdef _SOME_MSVC_DEFINE
    #  define _throw(foo)
    #else
    #  define _throw(foo) throw(foo)
    #endif
    
    void myfunc1() _throw (CCustomException);
    

    或者,尝试在VisualStudio中禁用该警告。