static:        (Page 406)

In both C and C++ the keyword static has two basic meanings, which unfortunately often step on each other's toes.

1 Allocated once at a fixed address; that is, the object is created in a special static data area rather than on the stack each time a function is called. This is the concept of static storage.

2 Local to a particular translation unit( and local to a class scope in C++). Here, static controls the visibility of a name, so that name cannot be seen outside the translation unit or class. This also describes the concept of linkage, which determines what names the linker will see.

static variables inside functions         (Page 407)

C and C++ allow you to create a static object inside a function; the srotage for this object is not on the stack but instead in the program's static data area. This object is initialized only once, the first time the function is called, and then retains its value between function invocations.

static class objects inside functions      (Page 408)

The rules are the same for static objects of user-defined types, including the fact that some initialization is requred for the object. However, assignment to zero has meaning only for built-in types; user-defined types must be initialized with constructor calls. Thus, if you donot specify constructor arguments when you define the static object, the class must have a default constructor. This construction occurs the first time control passes through the definition, and only the first time.

static class object destructors        (Page 409)

Destructor for static objects(that is, all objects with static storage, not just local static objects) are called when main() exits or when the Standard C libraty function exit() is explicitly called. This means that it can be dangerous to call exit() inside a destructor because you can end up with infinite recursion. Static object destructors are not called if you exit the program using the Standard C library function abort().

In C++, the constructor for a global static object is called before main() is entered, so you now have a simple and portable way to execute code before entering main() and to execute code with the destructor after exiting().

Controlling linkage          (Page 412)

An object or function name at file scope that is explicitly declared static is local to its translation unit. That name has internal linkage. This means that you can use the same name in other translation units without a name clash.

static members in C++        (Page 424)

It would be ideal if the data could be stored as if it were global, but be hidden inside a class, and clearly associated with that class. This is a single piece of srotage for a static data member, regardless of how many objects of that class you create.

The definition must occur outside the class(no inlining is allowed), and only one definition is allowed. Thus, it is common to put it in the implementation file for the class.

For example,

class A{

  static int i;

};

int A::i = 1;

static array initialization        (Page 425)

it allows static const variable defines inside a class body. With static const of integral types you can provide the definitions inside the class, but for everything else(including arrays of integral types, even if they are static const) you must provide a single external definition for the member.These definitions have internal linkage, so they can be placed in header files.

For example,

class value{

  static const int size = 100;

  static const int sc[];

  static int cc[];

};

const int value::sc[] = {1,2};

int value::cc[] = {2,3};

static member functions        (Page 429)

You can also create static member functions that, like static data members, work for the class as a whole rather than for a particular object of a class.

You can call a static member function in the ordinary way, with the dot or the arrow, in association with an object. However, it is more typical to call a static member function by itself, without any specific object, using the scope-resolution operator.

For example,

class X{

  static void f(){}

};

int main()

{

  X::f();

}

A static member function cannot access ordinary data members, only static data members. It can call only other static member functions. Normally, the address of the current object(this) is quietly passed in when any member function is called, but a static member has no this pointer, which is the reason it cannot access ordinary members.

static initialization dependency        (Page 432)

Within a specific translation unit, the order of initialization of static objects is guaranteed to be the order in which the object definitions appear in that translation unit. The order of destruction is guaranteed to be the reverse of the order of initialization. However, there is no guarantee concerning the order of initialization of static objects across translation units.

Name control的更多相关文章

  1. 企业管理软件开发架构之七 Object Control设计与运用

    在做查询时,经常遇到一类需求.请看下面的SQL语句查询 SELECT * FROM Company WHERE CompanyCode='Kingston' AND Suspended='N' AND ...

  2. 文字处理控件TX Text Control的使用

    这几天一直在研究TX Text Control的使用,由于这方面的资料相对比较少,主要靠下载版本的案例代码进行研究,以及官方的一些博客案例进行学习,使用总结了一些心得,特将其总结出来,供大家分享学习. ...

  3. Sublime text 2/3 中 Package Control 的安装与使用方法

    Package Control 插件是一个方便 Sublime text 管理插件的插件,但因为 Sublime Text 3 更新了 Python 的函数,API不同了,导致基于 Python 开发 ...

  4. Java 性能分析工具 , 第 3 部分: Java Mission Control

    引言 本文为 Java 性能分析工具系列文章第三篇,这里将介绍如何使用 Java 任务控制器 Java Mission Control 深入分析 Java 应用程序的性能,为程序开发人员在使用 Jav ...

  5. Job for httpd.service failed because the control process exited with error code. See "systemctl status httpd.service" and "journalctl -xe" for details

    thinkphp 在Apache上配置启用伪静态,重启Apache1 restart 竟然失败了,报错 Job for httpd.service failed because the control ...

  6. Neural Pathways of Interaction Mediating the Central Control of Autonomic Bodily State 自主神经系统-大脑调节神经通路

    Figure above: Critchley H D, Harrison N A. Visceral influences on brain and behavior[J]. Neuron, 201 ...

  7. Ubuntu[1]安装Vesta Control Panel

    参考:http://www.5013.org/archives/819 1)登录 ssh ubuntu@139.199.9.173 ubuntu@139.199.9.173's password: 重 ...

  8. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' heade

    XMLHttpRequest cannot load http://10.164.153.37:8050/WebService/WebService.asmx/wsGetStreetData. Res ...

  9. Sublime Text 3 安装Package Control

    原来Subl3安装Package Control很麻烦,现在简单的方法来了 一.简单的安装方法 使用Ctrl+`快捷键或者通过View->Show Console菜单打开命令行,粘贴如下代码: ...

  10. Optimistic Concurrency VS. Pessimistic Concurrency Control

    原创地址:http://www.cnblogs.com/jfzhu/p/4009918.html 转载请注明出处   (一)为什么需要并发控制机制 并发控制机制是为了防止多个用户同时更改同一条数据,也 ...

随机推荐

  1. JQuery Dialog 禁用X按钮关闭对话框,-摘自网络

    JQuery Dialog 禁用X按钮关闭对话框,禁用ESC键关闭代码如下:$("#div1").dialog({   closeOnEscape: false,   open: ...

  2. https://hub.docker.com/

  3. 教程-Win7极速优化20项

    1. 加快Windows 7系统启动速度     启动-“msconfig”命令-系统配置-“引导”选项(英文系统是Boot)-点击“高级选项”--勾选“处理器数”和“最大内存”.   2. 加快Wi ...

  4. hdoj 3861 The King’s Problem【强连通缩点建图&&最小路径覆盖】

    The King’s Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  5. 新发现:原来java正则表达式不写^和$也可以运行

    最近用了好多正则表达式,都是循规蹈矩的在前面加上^在后面加上$ 像这个样子"^[.]\\S+$",但实际上我在eclipse和editplus下都试了一下,不加前缀和后缀也是可以的 ...

  6. CoreLocation框架的使用

    CoreLocation框架使用 一.地图和定位的简介 1.应用场景 周边:找餐馆/找KTV/找电影院(团购APP) 导航:根据用户设定的起点和终点,进行路线规划,并指引用户如何到达(地图APP) 2 ...

  7. java中通过反射获取方法并且调用(getMethod和invoke深入)实践

    为了支持业务的快速变更,往往采用可配置的方式,将业务逻辑的处理部分配置在数据库中或者XMl文件里.配置什么,如何配置才更灵活,That's a problem. 以数据库配置为例(xml相同),在数据 ...

  8. EasyUI Datagrid 自定义列、Foolter及单元格编辑

    1:自定义列,包括 Group var head1Array = []; head1Array.push({ field: 'Id', title: 'xxxx', rowspan: 2 }); he ...

  9. GROUP BY,WHERE,HAVING之间的差别和使用方法

    having子句与where有类似之处但也有差别,都是设定条件的语句.在查询过程中聚合语句(sum,min,max,avg,count)要比having子句优先运行.而where子句在查询过程中运行优 ...

  10. linux中安装easy_install(setuptools)

    假设是相似于ubuntu的带桌面的系统直接下载安装就能够了.下面是针对centOS的命令行安装方法 最好先查看版本号号,依据版本号来选择安装方法.终端命令例如以下 # lsb_release -a 版 ...