Static member functions
Contains the keyword static when declared. Note the following two points:
1. A static member function cannot be invoked by an object or this pointer, but only by using the class name + scope resolver.
2. Static member functions can only use static members.
New operator
When using
The new operator can then specify the memory location when allocating memory. For example:
1 //Create a 512-byte memory buffer2 Char*buffer =New Char[ +];3ClassName *PTR1, *ptr2;4 5 //create a Class object in the buffer buffers6PTR1 =New(buffer) ClassName;7 //create a Class object in the heap8PTR2 =NewClassName;9 Ten Deleteptr1; One Delete[] buffer;
Delete ptr1 calls the destructor for the class, and delete [] buffer removes only the buffer buffers, not the destructor of the calling class. A viable option at this time is to show the call destructor before releasing buffer .
Nesting
C + + allows structs, classes, and enumeration definitions to be included in a class.
The scope of these types is the entire class.
This declaration does not create a data object , but it specifies that the type can be used in the scope of the class.
Member initialization syntax
1, can only be used for constructors.
2. A non-static const member must be initialized this way.
3. Reference data members must be initialized like this.
The format is as follows:
Classname::classname (int N): Mem1 (n), mem2 (0), mem3 (null) { // Construct .... }
After the colon, mem1,mem2,mem3 are data members that are classname, and the order of initialization is consistent with their order in the class declaration.
C + + supplements (10) class with dynamic memory allocation (2)