如何摆脱“C”++忽略异常规范”警告
我最近得到了一个别人已经实现的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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,这是一个非答案,但我会丢弃异常规范并且不再使用它< /a>.
编辑:我读得太快了,我没有看到你没有自己写这门课。消除 msvc 中警告的最佳方法是通过 #pragma warning(push) 后跟 #pragma warning(disable:xxxx),其中 xxxx 是警告代码:
编辑:禁用警告是完全安全的。异常规范是邪恶的,编译器只是告诉你它正在为你禁用它们。即使它违反了标准。
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 :
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.
您可以尝试使用预处理器:
或者,尝试在 Visual Studio 中禁用该警告。
You might try playing with preprocessor:
Or, try to disable that warning in Visual Studio.