Exception specification when overriding a virtual 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"
精彩评论