This is an article I saw on the Antibody Programming Network (http://www.5xsoft.com).
It's not bad, it's posting it to everyone.
1. When the pointer is passed, we can modify the content pointed to by the pointer. However, if you want to modify the object pointing to the external pointer is not possible. For example, the external pointer to the function is transmitted to allocate space, and the pointer to the pointer or pointer must be passed. 2. CHAR Carry [10] = {0}; the compiler will place all things thereafter 0; 3. When the function returns a value, the returned thing is paid to a type of the same name, it cannot be left value. ; 4. Const * i; int * const * i; int * const i; the first two functions are the same, indicating that the content points to the i is unchanged; the last description pointer points to the address constant, but the content varies. 5. Const member functions in the class. Defined as a CONST after prototype. Constant functions cannot modify any properties in the class. But there are two ways to modify. a) {(myclass *) THIS-> MEMBER1 = VALUES;} b) Define a member to Mutable by a constant function to modify. 6. The constant const type in the class cannot be used in the class to define an array. ENUM {One = 100; TWO = 2}; defined one, TWO can be. Usually, an ENUM definition problem: enum a {l = 9, z}; the value of z is 10.7. The intment definition with const can be used to open an array, but the elements in the constant array of constings cannot be Used to define an array. 8. Calculate the space of the variable with the sizeOf, if it is an array, press the actual space to return; constant strings (actually the variable opened in a static memory area) SIZEOF returns to the actual length plus one. If it is a pointer, it is not considered to point to the space size, and only returns the size of the pointer type. If you use the SizeOf to calculate the row ginseng, even if the group is also returns a size of a related type pointer. 9. Shaped like int aRray [] = {12, 124, 433}; the compiler will automatically assign the length of the three elements to IARRAY. The number of element lengths is calculated as a sizeof (IARRAY) / SIZEOF (* IARRAY). 10. Copy Construction Function: When the collections and the actual parameters are combined, if the transmitted value of the complex object is called, the calling constructor generates a temporary object as an argument, and the temporary object is sent to the destructor is released. When the return value is a complex object, it is also a call copy constructor to assign a value. This will appear in cases where the constructor and the destructive function are not equal. The prototype of the copy constructor is A (A &), we can overload in the class. (The default copy constructor is a bit (bit) copy method: shallow copy, no copy of the pointer points to the content). 11. Volithile type variable tells the compiler, this variable does not need to optimize code optimization. In multi-threaded applications, if we read a variable to the register, at this time, the time film expires, dealing with other threads, when re-obtaining the process, the Volatile type tells the process, and read data from the variable to the register. Instead of direct processing with register data, it can prevent dirty data. 12. Class and struct have the same function to some extent, but only the former default members are private, the latter is common in the default member. Therefore, Class is not a reserved word 13. C and C compiler required for C , which is different after compiling the same function name, so it is necessary to use Extern "C" to tell the compiler when referenced by reference to the library files referenced. C function, compile according to the rules of C. Usually we use the standard header files have been processed.
14. #include "filename"; #include
The static member variable of Main () {} class can be assigned: INT x :: S = 23; (in * .cpp, no matter how private private privacy) 21. Namespace: Define a name space, then use unsing You can convert the current type context to the name space .Namespace Math {ENUM SIGN {Positive, Negative}; Class Integer {Int i; Sign S; Public: Interger (int i = 0): i (i) {... ...} SIGN SIGN () {.........} ......................}; // end ClassInterger A, B, C; Interger Divide (Interger);} // no; void q () {Using Namespace Math; Interger A; // Hides Math :: aa.sign (negative); Math :: A.SIGN (Positive);} 22. General for Functions Flaot F (Int A, INT B); Some C After compiler, generate _f_int_int's name, some C compiler generates _f's name. Therefore, in the library function of the C , use externaln "c" to tell the compiler, press the rule to compile functions. Similar to extern "c" {# include "myhead.h"}, C also supports Extern "C " {}. 23. When the function is called, the pass reference is also a pointer stack. 24. Constructing function, destructuring function, assignment constructor, overloaded =, four call sequences: (three functions have been implemented) a) x x; x a = x; Result: x: Construct x: Copy_structb X x; x a; a = x; result: x: constructx: constructX: COPY_STRUOPERATOR = x: Destructure If there is no assignment function result: x: constructx: constructoperator = x: destruct (if directly x a = x; Do not drop with the general constructor, call the copy constructor) Pointer to the member function to the class: set int x :: A (void) {} x x; int (x :: * pf) (void) = & x :: a; (x. * pf) (); pointer to a member variable: set int i; is a member variable INT x :: * pm = & x :: i; x: x: x: x:
x. * pm = 12; x * p = & x; p -> * pm = 11; 25. operator overload const x & operator () // b; const x operator (int) // b ) The second parameter is dumb, never use. 26. Automatic type conversion a.) Class One {b} class two {public: one () {} public: two (const one "; void f (two; f)}} main () {on} (ONE);} At this time, a constructor in TWO is called for automatic conversion of the type. But the efficiency is not high. You can block an implicit type conversion. The method is as follows: Two TWO is given to class two {public: explicit two (const one &) {}}; ExPlicit only works on constructor. The function must be called this at this time: F (two); 27. An ideal String class, it knows how to convert from String to Char *: Class string {private: char * s; public: string (const char * s = ") {s = new char [strlen (s) 1] Strcpy (s, s);} ~ string () {delete s;} operator const char * () const {return s;}}; int main (void) {String str1 ("lizhihui2"); string str2 (" Lizhihui2 "); strcmp (str1, str2);} 28. If there is a variety of conversion methods from one type to another clock, it will be erroneous: classss y; class x {public: operator y () const; // convert x to y}; class y {public: y (x ); // converT x to y}; void f (y); main () {x x; f (x); // error: Ambiguous converness} 29. Delete array object: foo * fp = new foo [100]; delete [] fp; or delete [100] fp; make pointer more like array: int * const Q = new int [10]; this Q cannot be moved more like Array.
30. NEW 堆 memory function void out_of_memory () {Printf ("out of memory! / n"); exit (1);} main () {set_new_handler (out_of_memory); ...............} 31. NEW and DELETE a global overload method void * operator new {printf ("Operator new:% D Bytes / N", SZ); void * m = malloc (SZ); if (! m) PUTS ("OUT of Memory / N"); Return M;} Void Operator Delete (Void * M) {PUTS ("Operator Delete./N"); Free (m);} Class S {Int i [100]; public : S () {PUTS ("S :: S ()");} ~ s () {PUTS ("s :: ~ s ()");}}; int main (int Argc, char * argv [] ) {Int * p = new int (23); // Operator new: 4 bytes delete p; // operator delete. S * pp = new s; // operator new: 400 bytes delete pp; // Operator delete. S * PA = new s [3]; // Operator new: 1208 bytes, more 8 bytes for array info delete [] pa; // Operator delete. (C bilder unsupport) Return 0;} Default system New and DELETE is to call Malloc and Free, and the system should maintain a memory allocation table. The assigned memory should remember its size and start addresses, and release the address based on the start of the address. 32. Overloading NEW allocates space Class S {INT I; PUBLIC: S (INT IX = 0) {PUTS ("s :: ~ s ()");} Void * Operator new (size_t d, void * loc) {return loc;}}; int main (int Argc, char * argv [in [10]; s * ps = new (len 1) s 3412); // The first function is equivalent to telling the NEW where to start allocating space (implicit); // It is the length to be assigned. Special assignments should be taken to take special release. Return 0;} New allocates the space to the S object on the space of the LEN.
(New heavy load first parameters must be automatically transmitted to it to a size size) 33 for the SIZE_T system. Jump function setjmp, longjmpvoid oz () {Printf ("there 's no placelike home / n"); longjmp (kansas, 47);} jmp_buf kansas; int main (int Argc, char * argv []) {if ( SetJMP (Kansas) == 0) oz (); Else Printf ("i Have A Dream ../ n"); Return 0;} // After performing oz (), you will immediately jump to Printf ("i Have A DREAM ../ n "); Execute SetJMP () is a special function, when called, it is put in the current process status in BUFF and returns 0; if you use longjmp to the same BUFF Operation, this is like returning from SetJMP again, that is, the back end of SetJMP correctly pops up. At this time, the return value is the second parameter for longjmp, so it can be found that it is actually returned from longjum. 34. Abnormally customized and throw Class Up {}; Class Fit {}; void g (); Void F (INT i) throw (Up, FIT) {Switch (i) {casse 1: throw up (); case 2: throw Fit ();