[补充]C++存储修饰符--生存空间详细解释
来源:互联网 发布:找淘宝女鞋货源 编辑:程序博客网 时间:2024/06/07 06:40
C++ names can be used only in certain regions of a program. This area is called the “scope” of the name. Scope determines the “lifetime” of a name that does not denote an object of static extent. Scope also determines the visibility of a name, when class constructors and destructors are called, and when variables local to the scope are initialized. There are five kinds of scope:
- Local scope. A name declared within a block is accessible only within that block and blocks enclosed by it, and only after the point of declaration. The names of formal arguments to a function in the scope of the outermost block of the function have local scope, as if they had been declared inside the block enclosing the function body. Consider the following code fragment:
{ int i;}
Because the declaration of
i
is in a block enclosed by curly braces,i
has local scope and is never accessible because no code accesses it before the closing curly brace. - Function scope. Labels are the only names that have function scope. They can be used anywhere within a function but are not accessible outside that function.
- File scope. Any name declared outside all blocks or classes has file scope. It is accessible anywhere in the translation unit after its declaration. Names with file scope that do not declare static objects are often called “global” names.
- Class scope. Names of class members have class scope. Class member functions can be accessed only by using the member-selection operators (. or –>) or pointer-to-member operators (.* or –>*) on an object or pointer to an object of that class; nonstatic class member data is considered local to the object of that class. Consider the following class declaration:
class Point{ int x; int y;};
The class members
x
andy
are considered to be in the scope of classPoint
. - Prototype scope. Names declared in a function prototype are visible only until the end of the prototype. The following prototype declares two names (
szDest
,szSource
); these names go out of scope at the end of the prototype:char *strcpy( char *szDest, const char *szSource );
- [补充]C++存储修饰符--生存空间详细解释
- C++存储修饰符解释
- PHP正则表达式的修饰符详细解释
- 修饰符在python函数中的用法详细解释
- C++存储修饰符解释 zosatapo(原作)
- C语言 数据类型修饰符与存储类修饰符
- ORACLE-存储结构(2)-表空间(补充)
- java中的权限修饰符补充
- java基础: protected default 修饰符 补充
- java修饰符(待补充)
- IE内存泄漏补充:关于循环引用的详细解释
- c:each标签详细解释
- 进程的存储管理详细解释
- 关于常见的变量修饰符: const, static, extern, register, auto 的详细解释,使用场合以及注意事项
- c register修饰符
- C中的修饰符*()[]
- C语言修饰符
- C修饰符const
- javascript/Jscript实现父子窗体的互相引用问题(Powered By ZosaTapo)
- 不刷新页面动态更新select选项,实现两个select相互操作
- 网页输入框日期型有效性判定一网打尽
- 利用JScript/CSS 编程技术模拟实现TABView控件
- C++存储修饰符解释
- [补充]C++存储修饰符--生存空间详细解释
- JAVA中动态性实例解释
- JAVA多态性<==>我和网友交流实录
- 理解C++面向对象编程[多态性部分]
- C++语言中数组指针和指针数组彻底分析(系列一)
- 补充内容:C++语言中数组指针和指针数组彻底分析
- JAVA与C++::关于JNI中文字符串操作问题总结
- win95与win2000的关机与重启
- VSS与Jbuilder5/6进行代码控制的说明书