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

发布于 2024-09-08 00:39:57 字数 630 浏览 2 评论 0原文

我最近得到了一个别人已经实现的dll。我必须在我的应用程序中使用它。在他们的类的头文件中,他们有函数声明

void func1() throw (CCustomException);

现在当我编译它时收到警告,

忽略 C++ 异常规范 除了表明函数不是 _declspec(不抛出)

我阅读了 MSDN - 文档 但无法清楚地理解它。另外,我不想仅仅因为警告出现就禁用它。我想知道我做错了什么而不是禁用它。

我认为我的函数, myfunc() 从 dll 访问 func1() 没有该异常规范列表。因此,我也尝试在我的函数中包含相应的异常规范列表,

void myfunc1() throw (CCustomException);

但我仍然收到警告。该警告是什么意思以及如何消除它?我在 Windows XP 中使用 Qt 4.5。

I recently got a dll that has been implemented by others. I have to use it in my application. In the header file of their class they have the function declaration

void func1() throw (CCustomException);

Now when i compile it am getting the warning,

C++ exception specification ignored
except to indicate a function is not
_declspec(nothrow)

I read the MSDN - Documentation but couldn't understand it clearly. Also, I don't want to disable the warning just because it is showing up. I want to know what I am doing wrong instead of disabling it.

I thought my function, say myfunc() accessing that func1() from the dll doesn't have that Exception specification list. Hence I tried having the corresponding exception specification list in my function too as,

void myfunc1() throw (CCustomException);

But I am still getting the warning. What is that warning is all about and how to get rid of it? I am using Qt 4.5 in Windows XP.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

枫林﹌晚霞¤ 2024-09-15 00:39:57

好吧,这是一个非答案,但我会丢弃异常规范并且不再使用它< /a>.

编辑:我读得太快了,我没有看到你没有自己写这门课。消除 msvc 中警告的最佳方法是通过 #pragma warning(push) 后跟 #pragma warning(disable:xxxx),其中 xxxx 是警告代码:

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

...

#ifdef _MSC_VER 
#pragma warning(pop)
#endif

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

Ok, it is a non-answer, but I would throw away the exception specification and never use it again.

EDIT: I read too fast, and I didn't see you did not write the class yourself. Best way to get rid of warnings in msvc is via #pragma warning(push) followed by #pragma warning(disable:xxxx) where xxxx is the warning code :

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

...

#ifdef _MSC_VER 
#pragma warning(pop)
#endif

EDIT: It is perfectly safe to disable the warning. Exception specifications are evil, and the compiler is only telling you it is disabling them for you. Even if it breaks the standard.

dawn曙光 2024-09-15 00:39:57

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

#ifdef _SOME_MSVC_DEFINE
#  define _throw(foo)
#else
#  define _throw(foo) throw(foo)
#endif

void myfunc1() _throw (CCustomException);

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

You might try playing with preprocessor:

#ifdef _SOME_MSVC_DEFINE
#  define _throw(foo)
#else
#  define _throw(foo) throw(foo)
#endif

void myfunc1() _throw (CCustomException);

Or, try to disable that warning in Visual Studio.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文