Inline can be placed in. cpp, but only this CPP file can use it at this time.
To make a public object, you must put it in. H. If you do not want to put it in. H, you must copy one copy of each CPP file.
In fact, even if it is put in. H, it is also a copy of each CPP file, but the compiler completes this copy for you.
If the inline function is repeated, it will not cause a connection error. That is, it can be defined repeatedly. So it is an exception. Can other functions (the functions shown in the header file) be repeated?
Const in C ++ is actually a special variable. Except that you are not allowed to modify its value, there is no difference between it and the variable in other aspects (a duplicate number should be added for any two words.
The default scope of const is extern.
Const int x = 1234;
This type of header file is very common. And it is equivalent:
Extern const int x = 1234;
If you remove the const
Extern int x = 1234;
But extern int x = 1234; is not allowed to appear in the header file, because it may cause a connection error.
Extern int X; it is a variable declaration, and extern int x = 1234; it is a variable declaration plus definition. Variables can be declared repeatedly, as long as they do not conflict with each other, but can be defined only once.
However, const int x = 1234; is also the global definition of "variable" (if declared, it should be const int X;), but can appear in the header file, when multiple CPP files contain this header file, it is equivalent that each CPP file has a definition of "global variable" x. This is legal, so it is also an exception.
_---------------------------------------------------------
Inline is placed before the declaration of the function. do not add any more during implementation. inline only sends an application to the compiler, telling the compiler that my function is intended to be an inline function. The Compiler determines the result based on the actual situation. this function may be used as an inline function.
"Const object and inline functions are" one-time definition rules "exceptions? "
The implementation of the inline function is equivalent to copying a piece of code to. cpp. If it is repeatedly defined, no connection error will be generated.
The scope of the const object is limited to the current. cpp. Therefore, when you repeatedly define a const object, your own const object will appear in every. cpp object without symbol conflict!
---------------------------------------------------------
In C, defining a const object will allocate space, and the space has a global
Therefore, if a const is defined in the header
If the source file is included, the multiply defined symbols error is generated.
You can change the link property of static to local.
In C ++, const has a static link domain by default. Therefore, in C ++, you can
Define Const.