Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
A Complete Guide to Programming in C++ part 23. This book provides both novice and experienced programmers with a comprehensive resource manual for the C++ programming language. Readers gain experience in all aspects of programming, from elementary language concepts to professional software development, with in depth coverage of all the language elements en route. These elements are carefully ordered to help the reader create useful programs every step of the way. | STORAGE CLASSES OF OBJECTS When an object is declared not only are the object s type and name defined but also its storage class. The storage class specifies the lifetime of the object that is the period of time from the construction of the object until its destruction. In addition the storage class delimits the part of the program in which the object can be accessed directly by its name the so-called object scope. Essentially an object is only available after you have declared it within a translation unit. A translation unit also referred to as module comprises the source file you are compiling and any header files you have included. As a programmer you can define an object with block scope file scope program scope The object is only available in the code block in which it was defined. The object is no longer visible once you have left the code block. The object can be used within a single module. Only the functions within this module can reference the object. Other modules cannot access the object directly. The object is available throughout the program providing a common space in memory that can be referenced by any program function. For this reason these objects are often referred to as global. Access to an object as defined by the object s storage class is independent of any access controls for the elements of a class. Namespaces that subdivide program scope and classes will be introduced at a later stage. Lifetime Objects with block scope are normally created automatically within the code block that defines them. Such objects can only be accessed by statements within that block and are called local to that block. The memory used for these objects is freed after leaving the code block. In this case the lifetime of the objects is said to be automatic. However it is possible to define objects with block scope that are available throughout the runtime of a program. The lifetime of these objects is said to be static. When the program flow re-enters a code block .