Beginners in the study of object-oriented programming language, more or less questions, we write the code and the final compiled code is very different, we do not know what the compiler does in the background to do the work. These are the reasons
Life cycle of an objectCan be divided into static life cycle and dynamic life cycle1. Static life cycleIf the lifetime of an object is the same as the run time of the program, we call it a static Lifetime. Objects declared in the scope of a file
My C ++ notes (data sharing and protection) and notes
* Data sharing and protection: * 1. Scope: * scope is a region where an identifier is valid in the body of the program. In C ++, the identifiers have the function prototype scope, local scope
Assigning values to ObjectsIf two or more objects are defined on a class, the objects can be assigned to each other, or the value of one object can be assigned to another object of the same type. The value referred to here refers to the value of the
C + + class occupies memory size calculationPlease indicate the source and the author's contact information when reproduced.Article Source:http://blog.csdn.net/chenchong08Author contact information:[email protected]Description: The author's
1. The first and most important article is to introduce it: hide. (static function, static variable all available)When multiple files are compiled at the same time, all global variables and functions that do not have a static prefix have global
From a smaller program to a more complex program, the header file and the content of the source file is troubled for a long time, especially in the header file in the content, search for articles and a summary, if there is any mistake or debatable
If a class has only a class name defined, no methods and fields are defined, such as class a{}; Each instance of class A consumes 1 bytes of memory, and the compiler will insert a char in this instance to ensure that each instance of a has a unique
In C + + classes, static data members and (static) function members defined by static are classes, whereas members and functions that are not defined by static are called instance data members and instance function members, and they belong to an
Examples of file reading and writing in PythonWhen beginners are learning object-oriented programming languages, they are more or less doubtful that the code we write is quite different from the code that was compiled in the end, and we don't know
Three features summary :
share :
allocating memory in the global data area will only have one copy.shared by function (where static local variables are called multiple times)To be shared by (all) objects of the class in which the static method or
There are three main functions of static:(1) Local static variables(2) External static variables/functions(3) static data member/member functionThe first two C and C + + have, the third is only in C + +, the following are described below:First,
If A class only defines the class name and does not define any methods or fields, such as class A {}; then each instance of class A occupies 1 byte of memory, the compiler inserts A char in this instance to ensure that each A instance has a unique
Logitechyan static variables in C #C # Static variables are declared with the static modifier, created when the class is instantiated, accessing variables declared with the static modifier without a static variable called nonstatic variables,
In a class, static members can share data between multiple objects. Using static data members does not undermine the hidden principle, which ensures security. Therefore, static members are shared among all objects of the class, rather than members
Today and the small partners to discuss the third chapter of data semantics refers to some of the knowledge, it is necessary to summarize, it seems not to summarize knowledge will slip away, so take the night to write it.First look at an example of
Keywords
Mutable is an uncommon keyword in C ++. It can only be used for non-static and non-constant data members of a class.We know that the state of an object is determined by the non-static data member of the object. As the data member
Static member features
Static member functionsNo this pointer.
Static member functionsCannot be declared as Const.
Static member functionsCannot be declared as a virtual function.
Static member functionsYou can directly access static
In a class, static members can share data between multiple objects. Using static data members does not undermine the hidden principle, which ensures security. Therefore, static members are shared among all objects of the class, rather than members
The pointer to a data member is a mysterious and useful language feature, especially if you need to investigate the underlying layout of class members in detail. This investigation can be used to determine whether the vptr is placed at the beginning
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.