Constructor
a. The constructor must be the same as the class name, and the return type must not be declared;
b. You can use a line group to assign initial values, which can be overloaded;
C. Returns a pointer that cannot be passed to its first address of the object;
d. No parameters are called the default constructor;
e. There is a special initialization mode called "Initialization Expression Table" (referred to as initialization table). Initialization Table After the function parameter table, the function body {}, the rules:
1 If inheritance, the derived class must call the constructor of the base class in the initialization table;
Class B: public a {...};
B :: b (int x, int y): a (x) {};
2 CONST constants can only be initialized in the initialization table, and cannot be assigned in the function;
Class F
{
PUBLIC:
F (int X, int y);
Private:
INT MX, MY;
Int Mi, MJ;
}
Members of the class can initialize two ways to assign values in the initialization table or function.
F :: f (int X, int y): MX (X), My (Y)
{mi = 0; MJ = 0;}
F: f (int X, int y)
{mx = x; my = y; mi = 0; MJ = 0;}