After a semester study. Various structures have been achieved. Recently, this implementation code is found that because of the limited level, there are many unsafe busines in the code, so determine the reconstruction code.
first step. Try to use the const modifier to prevent data being accidentally modified.
1. Const function ginseng. ?? Is the Void Fun (? Char *) changed to Void Fun (const chat *), so that the function can accept no left value. Such as functional arguments, expressing real parameters, etc. 2. Const Return value, ???? Is it like a BOOL? FUN (VOID)? Change to const bool fun? (void) ?????? Furthermount the function value safely returned, ???? But there is a trouble. When the return value is a pointer, the type does not match the type of the call end?: For example: ?? const Int? *? Fun (void); ?? int * p = fun (); // must be wrong,? Solution There are two. ?? 1, if you do not need to let P point to point out. Then can be changed to a const? Pointer ????? Const INT * P =? Fun (); ?? 2. Using forced type conversion: ?????? Int? * P = (int *) Fun ( ); ??? ?? Disadvantage: syntax is ugly. But sometimes you must, such as P is a member of a class. It is generally not available for const modification, 3. Const member function ?? Shape? Int fun ()? Change to Int fun () const ???? Note: This function must be made to make sure that the function does not change any class members.
Step 2: Each class supplemental constructor, and operator set,
Considering 1, it is possible to support generic containers, such as the vector requirement to copy constructor, consider 2. Provide interface diversification to prevent some unnecessary type conversions. Such as: cstring and string, trouble, some structures require recursion. Such as binary trees, copy construction is difficult to achieve. Solve: another COPY function is defined. Source code See the [header file] C in the source code classification to implement two fork trees,
Step 3, type parameters, use templates
Consider, I want to support generic algorithms, difficult, and have not yet been realized. Waiting for the next reconfiguration, ??????????????????????????????