C ++ learning points

zhaozj2021-02-17  50

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 set all things thereafter. 3. When the function returns a value, the returned thing is paid to a type identical indicator. ; 4. const * i; int * const *, 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 defined setup problem: enum a {l = 9, z}; at this time, the value of Z is 10. 7. Int defined with const can be used to open an array, but the elements in the constant array definitions 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 former is first looking for files in the current directory. If you can't find it to find it to the system specified, the latter is directly to the path specified by the system. 15. The static variables allocated anywhere, the lifecycle and the main process is the same. The second time defines an existing STATIC variable, which has no effect on the variable, but its visible range is only within the defined range. (The postgraduate has made a mistake!) (It is not difficult to understand the characteristics of static variables, and the Static type in the class is shared by all objects) 16. Inline function (inline) is implemented in the actual and macro, the place in the inner function Expand the function to avoid the outlook in the function call, such as stack, improve efficiency. But the price of the inline function is: the code is increased. The inline function is suitable for member functions and free functions. The function implemented in the class is automatically inlined function. Inline must be defined to the implementation of functions, for example: Inline int plusone (int) is invalid. The friend function is automatically changed to the inline function in the body of the class. 17. #include #define debug (x) cout << # x "=" << x << Endl #x represents x is used as a string output. 18. Assert (0! = 0); if the conditions in Assert are false, return the program during the run, and report the line number of the error code. (#Include ) 19. Static object calls itself during the MAIN end or exit () is called. This means that in order to call exit () in an object's destructor, it is possible to enter a dead cycle. Calling Abort () to exit the function, the destructor of the static object is not called. We can use ATEXIT () to specify the operation you want to perform when you jump out of the MAIN or call EXIT, and use the ATEXIT registration function to call the destructor's destructor. Void exit_fn2 (void) {Printf ("exit function # 2 called / n");} // handle function ATEXIT (exit_fn2); 20. The global variable actually uses static storage. The structure of the static variable is called before entering Main, and it calls its destructor. The name of the variable is made of small range (C ): //*.cpp int a; // static variable, but extern int A; 即 即 is global, external visible Static Int B; // static variable, static In contrast to Extern, only in * .cpp is valid in * .cpp, it is invisible to other units (files). The definition of the function is the same.

转载请注明原文地址:https://www.9cbs.com/read-28740.html

New Post(0)