static 函数和 一般的函数有什么区别?
能不能给些例子
能不能给些例子
解决方案 »
- 如何加快socket下载速度?
- 组合框动态添加条目后鼠标消失,添加完使用ShowDropDown()自动弹出也只能显示一行,单击鼠标又出现,再点组合框,弹出行数正常,什么原因
- 高手来:MainFrame->xx窗口->button按钮如何响应这个按钮消息
- 怎么在diaog上拖动icon图片~
- 【求教】怎样使一控件透明?
- wtl问题??
- 求教,如何用VC编程读取Excel文件中某一个sheet的指定行列的单元格内容?请赐教!
- 各位老大,怎样将给定的中文根据拼音排序?
- 在ADO中不使用ODBC数据源如何直接连接SERVER数据库
- 编译没错却不执行,可能会是什么原因呢
- 200分,关于unicode问题我已经研究了好几天了,仍然未能解决。如果我的问题可以解决,立刻给,绝不食言!
- 得到deverxp提供的华为系统开发和编码规范实例文档(C/C++),十分高兴,散分,并请deverxp (刘德华)接分
static declaratorWhen modifying a variable, the static keyword specifies that the variable has static duration (it is allocated when the program begins and deallocated when the program ends) and initializes it to 0 unless another value is specified. When modifying a variable or function at file scope, the static keyword specifies that the variable or function has internal linkage (its name is not visible from outside the file in which it is declared). In C++, when modifying a data member in a class declaration, the static keyword specifies that one copy of the member is shared by all the instances of the class. When modifying a member function in a class declaration, the static keyword specifies that the function accesses only static members.For related information, see auto, extern, and register.Example// Example of the static keyword
static int i; // Variable accessible only from this filestatic void func(); // Function accessible only from this fileint max_so_far( int curr )
{
static int biggest; // Variable whose value is retained
// between each function call
if( curr > biggest )
biggest = curr; return biggest;
}// C++ onlyclass SavingsAccount
{
public:
static void setInterest( float newValue ) // Member function
{ currentRate = newValue; } // that accesses
// only static
// members
private:
char name[30];
float total;
static float currentRate; // One copy of this member is
// shared among all instances
// of SavingsAccount
};// Static data members must be initialized at file scope, even
// if private.
float SavingsAccount::currentRate = 0.00154;
即使类没有实例化,STATIC也可以存在
不象类的一些函数,必须在此类有对象存在的时候才有实体
static 函数没有隐含的THIS指针,不能访问成员变量