Exception specification when overriding a virtual function?

后端 未结 2 1048
轮回少年
轮回少年 2020-12-29 09:22

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

相关标签:
2条回答
  • 2020-12-29 09:27

    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.

    0 讨论(0)
  • 2020-12-29 09:41

    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 讨论(0)
提交回复
热议问题