1. The object's space is allocated at the beginning of the parentheses, but the construct is implemented when the object is defined, and if skipped (such as Goto), an error occurs when the parentheses end the destructor, but the compilation is not.
2. Initialization
1 structY ZintIfloatFCharc;};2 3-X x1 = {1,2.2,'C'};4X x2[3] = { {1,1.1,'a'},{2,2.2,'b'} };5 6 7 structYfloatFintI Yinta);} ;8 9Y y1[] = {Y (1), Y (2), Y (3)};
3. Default constructor = = Parameterless constructor
Y y2[2] = {Y (4);} // It is wrong
4. New/delete
NEW: Allocate space + call constructor
Delete (delete[]): First destructor, then reclaim space
int New int [ten]; Delete [] psome; // can't lose []
Do not use the delete to free space that is not new
Do not delete the same memory space two times
When using new[], you must use delete[]
New does not take [],delete nor
A null pointer to delete is safe (nothing will happen): not sure if new is used
No delete. Memory leaks.
int*p =New int;int*a =New int[Ten]; Student*q =NewStudent (); Student*r =Newstudent[Ten];DeleteP//address and size of Pa++;Delete[] A;//run error, unable to find the address of a at newDeleteQ//Recycling StudentDeleteR//the space is retracted, and the destruction only makes aDelete[] r;//Destructors All Objects
Only at compile time
--public: Common
--private: Self-member function of the class, two objects of the same kind can access the private variables with one another.
--protected:
Friend: Another class, a function inside another class.
structX//declaration of preceding paragraphstructy{voidF (x*); };structx{Private: inti; Public: voidInitialize (); FriendvoidG (x*,int);//Global friendFriendvoidY::f (x*);//Struct member FriendFriendvoidZ//entire struct is a friendFriendvoidh ();};
Class vs. struct
The class default is private
struct default is public
Preferred class
struct a{
Private
int i;
Public
A:I (0) {}
The order in which the assignment is implemented is before the constructor is executed, compared to the
Try to use initialization without assigning values
C + + Storage allocation + Dynamic memory allocation + setting limits + initializer list (1)