final specifier (since C++11)
Specifies that a virtual function cannot be overridden in a derived class or that a class cannot be inherited from.
Syntax
The identifier final, if used, appears immediately after the declarator in the syntax of a member function declaration or a member function definition.
| declarator virt-specifier-seq(optional) pure-specifier(optional) | (1) | ||||||||
| declarator virt-specifier-seq(optional) function-body | (2) | ||||||||
class-key attr(optional) class-head-name class-virt-specifier(optional) :base-specifier-list(optional) |
(3) | ||||||||
final may appear in virt-specifier-seq immediately after the declarator, and before the pure-specifier, if used.final may appear in virt-specifier-seq immediately after the declarator and just before function-body (which may begin with a member initializer list)final may appear as class-virt-specifier immediately after the name of the class, just before the colon that begins the base-specifier-list, if used.In the cases (1,2), virt-specifier-seq, if used, is either override or final, or final override or override final. In the case (3), the only allowed value of class-virt-specifier, if used, is final
Explanation
When used in a virtual function declaration or definition, final ensures that the function is virtual and specifies that it may not be overridden by derived classes. The program is ill-formed (a compile-time error is generated) otherwise.
When used in a class definition, final specifies that this class may not appear in the base-specifier-list of another class definition (in other words, cannot be derived from). The program is ill-formed (a compile-time error is generated) otherwise. final can also be used with a union definition, in which case it has no effect (other than on the outcome ofstd::is_final), since unions cannot be derived from)
final is an identifier with a special meaning when used in a member function declaration or class head. In other contexts it is not reserved and may be used to name objects and functions.
Example
struct Base
{
virtual void foo();
}; struct A : Base
{
virtual void foo() final; // A::foo is final
void bar() final; // Error: non-virtual function cannot be final
}; struct B final : A // struct B is final
{
void foo(); // Error: foo cannot be overridden as it's final in A
}; struct C : B // Error: B is final
{
};
See also
- override specifier (since C++11)
final specifier (since C++11)的更多相关文章
- 【final】站立会议---11.28
名称:nice! 组长:李权 成员:韩媛媛 刘芳芳 宫丽君 于淼 项目名称:约跑app 时间:11月28日 12:30 内容: 新任务的分配 1.李权分配任务 2.韩媛媛写站立会议 3.刘芳芳修改BU ...
- 【final】站立会议---11.27
名称:nice! 组长:李权 成员:于淼 刘芳芳韩媛媛 宫丽君 时间:11月27日 13:00 项目内容:约跑app(约吧) 地点:传媒西楼220室 内容: 新任务的分配 1.李权分配任务 2.韩媛 ...
- Google C++ Style Guide
Background C++ is one of the main development languages used by many of Google's open-source project ...
- Google C++ 代码规范
Google C++ Style Guide Table of Contents Header Files Self-contained Headers The #define Guard For ...
- 【Cocos2d-x游戏开发】细数Cocos2d-x开发中那些常用的C++11知识
自从Cocos2d-x3.0开始,Cocos2dx就正式的使用了C++11标准.C++11简洁方便的特性使程序的可拓展性和可维护性大大提高,也提高了代码的书写速度. 下面我们就来一起学习一下Cocos ...
- Java:final、static关键字 详解+两者结合使用
一 final关键字 1) 关于final的重要知识点 final关键字可以用于成员变量.本地变量.方法以及类. final成员变量必须在声明的时候初始化或者在构造器中初始化,否则就会报编译错误. ...
- 你真的知道final关键字吗?
概述 final在英文中是最终的,不可更改的.在Java中final修饰变量,函数和类,就像这个单词的意思,一旦使用赋值之后不可更改. final修饰的变量不可以被改变 finalTest类 publ ...
- [译] iOS 11.4.1 Beta:全新的USB限制模式
(Source/原文链接 https://blog.elcomsoft.com/2018/06/ios-11-4-1-beta-usb-restricted-mode-has-arrived/) 作者 ...
- Final阶段第1周/共1周 Scrum立会报告+燃尽图 06
作业要求[https://edu.cnblogs.com/campus/nenu/2018fall/homework/2485] 版本控制:https://git.coding.net/liuyy08 ...
随机推荐
- AXIOM
AXIOM是一个实现了延迟构造和拉(pull parsing)解析的轻量级的xml解析器 http://reeboo.iteye.com/blog/317391 http://reeboo.iteye ...
- dedecms 忘记后台密码
找到admin表 dede_admin,把其pwd的值修改为 默认的 字符串:f297a57a5a743894a0e4, 之后,你的密码就被充值为 admin
- zoj3261 带权并查集
题意:有很多颗星球,各自有武力值,星球间有一些联系通道,现在发生战争,有一些联系通道会被摧毁,而一些星球会通过还没有被摧毁的联系通道直接或者间接联系能够联系到的武力值最高的星球求救,如果有多个武力值都 ...
- 回调函数的实现 & 结构体的继承
------------------------------------------------------------------------------------[1]------------- ...
- 复利计算- 结对2.0--复利计算WEB升级版
客户在大家的引导下,有了更多的想法: 这个数据我经常会填.....帮我预先填上呗?...... 把界面做得简单漂亮好操作一点呗? 能不能帮我转成个APP,我装到手机上就更方便了? 我觉得这个很有用,很 ...
- docker学习3-虚拟网络模式
一.虚拟机网络模式 在理解docker网络隔离前,先看下之前虚拟机里对网络的处理,VirtualBox中有4中网络连接方式: NAT Bridged Adapter Internal Host-onl ...
- 用CorelDRAW勾画对象轮廓图的方法
轮廓图效果是利用渐变的步数来使图形产生渐变效果,与调和效果相似.两者的区别在于图形数不同,调和效果作用于两个或两个以上的图形,轮廓图只作用于一个图形.本教程将详解CorelDRAW中如何勾画对象轮廓图 ...
- unity, 读写xls
可以用npoi: http://npoi.codeplex.com/ 把npoi.dll放在unity里即可. 读取代码: using System.IO;using NPOI.SS.UserMode ...
- unity shader random number
http://gamedev.stackexchange.com/questions/32681/random-number-hlsl
- asp.net中HTML代码编码、解码与页面的重定向
http://www.cnblogs.com/yjss/articles/2005894.html 1.编码(输出的字符串中包含HTML代码) Response.Write(Server.HtmlEn ...