[補充]C++儲存修飾符--生存空間詳細解釋 (轉)
pe>
C++ names can be used only in certain regions of a program. This area is called the “scope” of the name. Scope detenes the “lifetime” of a name that does not denote an 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 ins 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-ion 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
. - scope. Names declared in a function prototype are visible only until the end of the prototype. The following prototype declares two names (
szDest
,sz
); these names go out of scope at the end of the prototype:char *strcpy( char *szDest, const char *szSource );
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10748419/viewspace-1006227/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- C++儲存修飾符解釋 (轉)C++
- C++儲存修飾符解釋 zosatapo(原作) (轉)C++
- Vue事件修飾符詳解Vue事件
- 禪道 - 儲存空間釋放
- PHP正規表示式模式修飾符詳解PHP模式
- C++函式修飾符總結C++函式
- C++繼承時的修飾符C++繼承
- C++學習——訪問修飾符C++
- Vue - 按鍵修飾符 && 系統修飾符Vue
- linux nfs共享儲存服務詳細解釋。LinuxNFS
- Java 修飾符Java 修飾符
- java修飾符Java
- set unused 是否會釋放儲存空間
- 關於Java中各種修飾符與訪問修飾符的說明 (轉)Java
- 開心檔之C++ 修飾符型別C++型別
- PostgreSQL儲存智慧-空間聚集儲存SQL
- Kotlin——中級篇(三):可見性修飾符詳解Kotlin
- vue 事件修飾符Vue事件
- vue sync 修飾符Vue
- 繼承&修飾符繼承
- iOS __block修飾符iOSBloC
- Java 常用修飾符Java
- 訪問修飾符
- C#中const 和 readonly 修飾符的用法詳解C#
- java中的修飾符Java
- Java的static修飾符Java
- 許可權修飾符
- 表空間遷移辦法補充
- 【儲存管理】表空間概念
- TypeScript 類訪問修飾符TypeScript
- Java的訪問修飾符Java
- java修飾符使用指南Java
- C++陣列的儲存|C++陣列所佔記憶體空間C++陣列記憶體
- 最詳細的解說—時間和空間複雜度複雜度
- [轉帖]OceanBase 儲存引擎詳解儲存引擎
- 【儲存管理】建立永久表空間
- innodb表空間儲存結構
- Java的“友好的”訪問指示符(修飾符)Java