1 Star 0 Fork 115

thornphoenix / CPlusPlusThings

forked from Yj / CPlusPlusThings 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
final.cpp 787 Bytes
一键复制 编辑 原始数据 按行查看 历史
light-city 提交于 2020-03-03 09:34 . update
//
// Created by light on 19-11-3.
//
#include <iostream>
using namespace std;
// final关键字用于两个地方
// 第一个用在类,用于说明该类是继承体系下最后的一个类,不要其他类继承我,当继承时就会报错。
class Base final {
public:
Base() {}
virtual void func() {}
};
class Derivered : public Base { // error: cannot derive from ‘final’ base ‘Base’ in derived type ‘Derivered’
};
// 第二个用在虚函数,表示这个虚函数不能再被override了,再override就会报错。
class Base1 {
public:
Base1() {}
virtual void func() final {}
};
class Derivered1 : public Base1 {
virtual void func() {} // error: overriding final function ‘virtual void Base1::func()’
};
int main() {
}
C++
1
https://gitee.com/thornphoenix_admin/CPlusPlusThings.git
git@gitee.com:thornphoenix_admin/CPlusPlusThings.git
thornphoenix_admin
CPlusPlusThings
CPlusPlusThings
master

搜索帮助