2 Star 1 Fork 2

陈首翱 / cppThings

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
final.cpp 787 Bytes
一键复制 编辑 原始数据 按行查看 历史
chenshouao 提交于 2022-01-20 19:37 . initlized
//
// 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() {
}
1
https://gitee.com/chen-shouao/cpp-things.git
git@gitee.com:chen-shouao/cpp-things.git
chen-shouao
cpp-things
cppThings
master

搜索帮助