gpt4 book ai didi

c++ - 标准对抛出异常的类型有什么要求?

转载 作者:行者123 更新时间:2023-11-30 02:08:27 26 4
gpt4 key购买 nike

I thought exceptions imposed a bit more on the thrown type than the standard actually imposes.我想澄清这个困惑。这些类型实际上强加了什么?

最佳答案

C++ ISO 规范,§15.1/3,指出

The type of the throw-expression shall not be an incomplete type, or a pointer or reference to an incomplete type, other than void*, const void*, volatile void*, or const volatile void*. Except for these restrictions and the restrictions on type matching mentioned in 15.3, the operand of throw is treated exactly as a function argument in a call (5.2.2) or the operand of a return statement.

由此看来,您应该能够抛出任何您想要的东西,只要您不抛出您仅转发声明的类型即可。

编辑:正如@Billy ONeal 指出的那样,类型必须是可复制的,这意味着它应该支持复制构造函数。

关于c++ - 标准对抛出异常的类型有什么要求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6864394/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com