是否需要覆盖和noexcept的顺序?
class Base { public: virtual void foo() {} }; class Derived : public Base { public: // virtual void foo() override {} // Ok // virtual void foo() noexcept {} // Ok // virtual void foo() noexcept override {} // Ok virtual void foo() override noexcept {} // Error }; int main() {}
我正在使用gcc 4.7.2.
解决方法
实际上,是的,它很难找到,因为它有点分散.附件A(语法摘要)在这方面有所帮助.让我们试着找到具体的位:
declarator: ptr-declarator noptr-declarator parameters-and-qualifiers trailing-return-type parameters-and-qualifiers: ( parameter-declaration-clause ) attribute-specifier-seqopt cv-qualifier-seqopt ref-qualifieropt exception-specificationot exception-specification: dynamic-exception-specification noexcept-specification noexcept-specification: noexcept ( constant-expression ) noexcept
然后是覆盖
member-declarator: declarator virt-specifier-seqopt pure-specifieropt declarator brace-or-equal-initializeropt identifieropt attribute-specifier-seqopt: constant-expression virt-specifier-seq: virt-specifier virt-specifier-seq virt-specifier virt-specifier: override final
所以声明符是包含noexcept关键字的东西,但是在member-declarator中,virt-specifier出现在声明符之后.