Sco*_*e T 4 static programming-languages keyword
我听说关于关键字含义的语言之间存在差异static
,但我没有找到一个合并这些差异的好列表.
以下是我对static
C++中的含义的了解:
static
其他语言的变化意义如何?
dir*_*tly 11
C
int a; // a has external linkage
static int a; // a now has static linkage
// same as if you wrote: static int a = 0;
//...
static int b; // static linkage
extern int b; // extern loses its meaning, b still has internal linkage
//...
extern int b; // b has external linkage
static int b; // error
//...
void func() {
static int x; // automatic linkage, static duration
// same as if you wrote: static int x = 0;
}
Run Code Online (Sandbox Code Playgroud)
C++
thread_local
说明符(从C++ 0x开始)this
指针用于此类函数this
在静态方法中使用动作脚本
this
或super
在静态方法面向对象设计
我可能错过了很多其他的东西 - 随意插入.
在Delphi中,static关键字专门用于定义类方法.在Delphi中,可以将普通类方法声明为虚拟并在子类中重写.另外Delphi有一个自变量,类似于其他语言中的this指针.但是在类方法中,self指向调用方法的类而不是实例.
声明类方法static意味着:
这意味着静态类方法只能访问其定义的类中的类成员,而普通类方法可以访问派生类中的重写类成员.
在Delphi文档中还有其他非正式的静态用法,通常指的是一个不可加入的特征(是一个单词?).例如静态数组与动态数组.除非另有声明,否则Delphi中的所有实例方法都是静态的