1:
Constants can be placed in header files, including constant strings, but constant strings should be defined as follows:
Const char * const pstr = "str ";
Const char STR [] = "str ";
2:
If the memory is insufficient, new runs out of a bad_alloc exception. If a handler function with insufficient memory is set, this function is either
Exit abort or find available memory! Otherwise it will be in an endless loop!
However, when operator new is called to allocate an airplane object, the resulting memory may be larger
You need more. This strange behavior occurs because operator new and operator Delete need to interact with each other.
Transfer information.
Therefore, we don't really care too much about the new failure issue, or capture the bad_alloc exception to let the program
3
Rewrite the copy constructor and value assignment constructor for classes that require dynamic memory
Do not return the internal data handle of the class. If you have to return the data, the const handle is returned.
Eg string: const char * operate ();
Or string: const char * c_str ();
////////////////////////////////
2009.9.9
1: Do not redefine the inherited non-virtual functions
2: Avoid downward conversion. You can try to implement it using virtual functions (downward conversion is generally to use a function of the derived class. If virtual functions are used, the function of the derived class is automatically used, can avoid downward conversion). Actually, it cannot. Use dynamic_cast <> Security Point.
3: You do not need to forcibly convert the return value of malloc (). It is better to use sizeof (* P) or sizeof (variable ).
4: How to Prevent the constructor from leaking resources: Try to catch any exceptions such as new. If any exceptions occur, delete all pointers.
The ultimate method is to use auto_prt <> to store pointers. This relies on the C ++ guarantee. Generally, if a class is constructed, its destructor can be called.
5. Accept exception objects by referencing
Pointers face the issue of deleting pointers.
Data transmission faces the cutting problem.