1. Basic knowledge C + +in theclassStarting from the object-oriented theory, the variable(Properties)and Functions(Method)centrally defined 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.
#include "iostream" using namespace Std;class c1{public:int i;//4 int J;//4int k;//4protected:private:}; 12class C2{public:int i;//4int j;//4int K;//4static int m;//4public:int getk () const {return k;}//4void setk (int val) {k = val;}//4protected:private:}; 12struct s1{int i;int j;int k;}; 12struct s2{int i;int j;int k;static int m;}; 12int Main () {printf ("c1:%d \ n", sizeof (C1));p rintf ("c2:%d \ n", sizeof (C2));p rintf ("s1:%d \ n", sizeof (S1));p rintf (" s2:%d \ n ", sizeof (S2)); System (" Pause ");}
2, four-zone interpretation with memoryC + +Properties and Methods2.1 C + +The member variables and member functions in the class object 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.
2.2 C + +compiler's internal processing of ordinary member functions
3, Summary:
The member variables and member functions in 3.1 C + + class objects are stored separately. Memory four-zone model in C language still works!
3.2 C + + The normal member function of a class implicitly contains a pointer to the current object. This pointer.
3.3 Static member functions, member variables belong 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
C/C + + Academy (7) A discussion of the object-oriented model