首先,final关键字在C语言中并不存在。
其次,C++11中增加了final关键字,应该是从Java语言中借鉴而来,用途也一样。示例代码如下:
#include <iostream>using namespace std
/* use final on a class to prevent inheriting compilation error */
class A /* final */ {
public:
/* use final on a method to prevent override compilation error */
virtual void func(int) /* final */ { cout << "A::func()" << endl }
}
class B : public A {
public:
/* use override to make the compiler checks that we are indeed overriding an inherited method */
virtual void func(int) override { cout << "B::func()" << endl }
/* virtual void func(char) override {} compilation error new method (see signature), does not override existing */
}
int main() {
A t
t.func(2)
B u
u.func(3)
}
1、最终的;最后的
The referee blew the final whistle.
裁判吹响了终场的哨声。
2、(指结果)最终的,最后的
No one could have predicted the final outcome.
谁也没有预想到最终结果会是这样。
3、决定性的;不可改变的;最终的
Who has the final say around here?
这里谁有最后决定权?
4、决赛
She reached the final of the 100m hurdles.
她取得了100米跨栏的决赛权。
扩展资料
final和last的辨析
1、 两者都可指顺序上的“最后”,有时可换用。如:
The final/last word in this dictionary is "Zoom".
这本词典的最后一个单词是"Zoom"。
2、 last 主要指一个系列 (如顺序、次序、时间等)的最后,含有再往后就没有了的意思。如:
He was the last to arrive.
他是最后一个来的。
3、final 不仅指顺序上的最后,而且含有以此作为结束或到达终点之意。如:
He failed in the final examinations.
他期中考试没有及格。
4、final可由“最后的”引申出“确定的”或“不能改变的”。如:
The decision is final.
这个决定不能改变。
c语言中静态变量作常量使用,用于存储常数。可用const,constant或final等关键字标识,其值就会在编译时设定,并且无法在运行时改变。编译器通常将静态常量与文本一起置于目标文件的文本区域,而非常量初始化数据则置于数据区;而如若有需要,有些编译器还可选择为其开辟专用区。
对于静态全局变量来说,针对某一源文件的以static声明的文件级变量与函数的作用域只限于文件内(只在文件内可见),也即“内部连接”,因而可以用来限定变量的作用域。
扩展资料:
在函数内以static声明的静态局部变量虽然与自动局部变量的作用域相同(即作用域都只限于函数内),但存储空间是以静态分配而非默认的自动分配方式获取的,因而存储空间所在区域不同。
一般来说,静态分配时存储空间于编译时在程序数据段分配,一次分配全程有效;而自动分配时存储空间则是于调用栈上分配,只在调用时分配与释放,且两次调用间变量值始终保持一致;必须注意,静态局部变量只能初始化一次,这是由编译器来保证实现。