Compiler's handling of properties and methods
The class in C + + is based on object-oriented theory, defining variables (attributes) and functions (methods) together to describe classes in the real world. From the computer's point of view, the program is still composed of data segments and code snippets.
How does the C + + compiler accomplish the transformation of object-oriented theory to computer programs?
In other words: how the C + + compiler manages relationships between classes, objects, classes, and objects
Specifically, the specific object calls the method in the class, that is, how the C + + compiler distinguishes, is that specific class, call this method that?
1) member variables and member functions in C + + class objects are stored separately
Member variables:
Normal member variables: stored in an object, with the same memory layout and byte alignment as the struct variable
Static member variables: stored in the global data area
member functions: stored in code snippets.
The problem is: many objects share a piece of code? How does the code differentiate between specific objects?
In other words: int getk () const {return k;}, how does the code differentiate between specific obj1, OBJ2, and Obj3 object K values?
The right side of the implementation of the C + + class is the corresponding underlying implementation.
Summarize:
1. member variables and member functions in C + + class objects are stored separately. Memory four-zone model in C language still works!
2. The normal member function of a class in C + + implicitly contains a pointer to the current object.
3. Static member function, member variable belongs to class
The difference between a static member function and a normal member function
Static member functions do not contain pointers to specific objects
The normal member function contains a pointer to a specific object
Expand:
Think: the member function of a class can be modified by a const, who is the const modifier?
void const GET (int A,INTB)//member function of class {this->a=100;//error this->b=200;//Error}
According to the above analysis internal implementation as
void get (const Test *this,int a,int B)
So the const modifies the memory space that the this pointer points to.
The above is the C + + review key summary of the six-compiler on the properties and methods of the processing mechanism of content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!