C++ study notes fourteen-constant objects, compile notes

Often for objects like this, the definition must be initialized and cannot be updated during the lifetime.
Form const type name object name

We know that a large project may contain multiple header files, for example as follows

//main.cpp
# include <test1.h>
# include <test2.h>
................


//test1.h
# include <rui.h>
..........
//test2.h
# include <rui.h>
...........
//rui.h
class point
{
    
    }

If you follow the above, because both test1.h and test2.h include rui.h, the point in the class will be included twice, and compilation errors will occur. In order to prevent this from happening, you can use pre-compilation methods. as follows

//rui.h
#ifndef rui_h
# define rui_h
class point 
{
    
    }
...
#endif

The above paragraph means that if the identifier rui_h is not defined, it means that the file is not compiled, then define this identifier, and compile this file, wait until the next compilation finds that the identifier is defined, ignore the following program segment directly .
The process of code compilation, linking and execution
Compilation: compile each cpp file to generate obj file, obj file contains code segment and data segment,
link: link each obj file, because different obj files have the same structure, so they can be linked to
Execute together : the execution of the program is based on the process

Guess you like

Origin blog.csdn.net/qq_41803340/article/details/114139741