开发者

Exception specification when overriding a virtual function?

开发者 https://www.devze.com 2023-02-16 10:34 出处:网络
If a class 开发者_StackOverflowinherits from another and overrides a virtual function, how must the exception-specification for the derived (overridden) function be related to the base function?

If a class 开发者_StackOverflowinherits from another and overrides a virtual function, how must the exception-specification for the derived (overridden) function be related to the base function?

Is that is must be at least as restrictive? right? or others?


Yes, it must be at least as restrictive (§15.4/3):

If a virtual function has an exception-specification, all declarations, including the definition, of any function that overrides that virtual function in any derived class shall only allow exceptions that are allowed by the exception-specification of the base class virtual function.


It is $15.4 p.5 in http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3242.pdf: "If a virtual function has an exception-specification, all declarations, including the definition, of any function that overrides that virtual function in any derived class shall only allow exceptions that are allowed by the exception-specification of the base class virtual function"

0

精彩评论

暂无评论...
验证码 换一张
取 消