Home >Backend Development >C#.Net Tutorial >A detailed discussion of c++11 final and override specifiers

A detailed discussion of c++11 final and override specifiers

高洛峰
高洛峰Original
2017-01-23 14:04:542086browse

As shown below:

//final,override出现在形参列表以及尾置返回类型之后
#include <iostream>
using namespace std;
struct B{
    virtual void f1(int) const;
    virtual void f2(int);
    void f3(int) final;//出错,final不能修饰非虚函数
};
struct D:B{
    void f1(int) const override ;//去掉const将出错,必须和基类中的函数原型一致,否则不能用override来表示覆盖
    void f2(int) final;//final说明继承D的派生类中不能覆盖该函数
    void f3();
};
struct E:B{
    void f2(int);//ok,其直接基类B中该函数没有final说明符
};
struct F:D{
    void f2(int);//出错,无法覆盖该函数,原因是其直接基类D中有final说明符
};

final means that the virtual function cannot be overridden, and override means that the function overrides a certain virtual function

The above article's detailed discussion of c++11 final and override specifiers is all the content shared by the editor. I hope it can give you a reference, and I also hope that everyone will support the PHP Chinese website.

For more detailed articles on c++11 final and override specifiers, please pay attention to the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn