标准中的覆盖顺序和noexcept的顺序 [英] The order of override and noexcept in the standard

查看:69
本文介绍了标准中的覆盖顺序和noexcept的顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

覆盖顺序是标准所必需的吗?

Is the order of override and noexcept required by the standard?

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.

I'm using gcc 4.7.2.

推荐答案

实际上,是的,很难找到它,因为它有点分散.附件A(语法摘要)在这里有所帮助.让我们尝试找到特定的位:

Actually, yes, it is, its just hard to find out, since its a bit scattered. Annex A (Grammar summary) is of some help here. Lets try to find the specific bits:

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关键字的内容,但是在成员声明符中,virt-specifier紧跟在声明符之后.

So a declarator is the thing that contains the noexcept keyword, but in the member-declarator the virt-specifier comes after the declarator.

这篇关于标准中的覆盖顺序和noexcept的顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆