Finally, I found that in the implementation file.CPP, I used using NAMESPACE STD;
Solutions:
1. Use count instead of ::count (because STD ::count is also in the STD namespace, the compiler is not sure if it is ::count or STD ::count)
Comment out the namespace
3. Or:
using std::cout;
using std::endl;
using std::cin;
Reflection summary:
I. Thinking using NAMESPACE STD
A lot of times it’s not a good idea to use this code (and more importantly: it’s best not to use it in header files)
A good habit is to use STD ::cout and STD ::cin
All the identifiers of the c + + standard library is defined in a namespace called STD, using namespace STD is to import all the system defined identifier, because of the standard library is very large, the programmer when choosing the name of a class or function name is probably has one of the same name, and the standard library that is your own definition of things (variables, methods, classes, etc.) and the system of the identifier name repetition, otherwise there will be a naming conflict error!
C++ definition of global variables
1. It is generally a good idea to declare global variables in a CPP file (if defined in a.h file, multiple layers contain errors that may cause duplication of definitions)
2. Once defined in CPP, you can use the extern keyword in the.h file for an extern declaration (the extern declaration represents the declaration that an externally defined variable is introduced here, rather than another local variable with the same name being declared in this compilation unit)
Then, when other files want to use these variables, just the #include header file is fine, and it won’t cause a double-definition error
3. Comparison of static global variables, global constants (CONST) and ordinary global variables:
1. Static global variables: They can’t be introduced with extern, i.e., extern and static cannot be used together. And static globals are quite different from normal globals.
Static modification of the scope of a global variable is just its own compilation unit (in this compilation unit changes to take effect), when used in other units, the variables have a new memory address, that is, each compilation unit USES it to it opened up a separate space, and make a copy of its original value, so if a unit to modify it, then its value in multiple compilation unit may not be the same
Note:
The static modifier is static, static, static, static, static, static, static, static, static, static, static.
Multiple units contain the static global header file, which doesn’t cause a redefinition error because each unit creates a new space to store it.
2. Global const variable: const like common global variables, global variables to use in a. CPP and initialization, defined in. H header file using extern declaration, then you need to use the place contains. H, its memory address is also different in the multiple compilation unit (this is similar to the static global variable), but because of is constant, not modify the value, so even if the memory address didn’t influence, different values are the same.
Also useless to, refer to: http://blog.csdn.net/jiadebin890724/article/details/40509333
Four, the use of namespaces
To be continued…
Read More:
- Global variable error: unboundlocalerror: local variable ‘l’ referenced before assignment
- Node configuration environment variable and global installation of webapck
- Python global variables and global keywords
- Error c2951: template declaration can only be used at the global, namespace, or class scope. Error c2598: link specification must be at the global scope
- variable ‘std:ofstream’ has initializer but incomplete type
- Differences between shell script variable assignment and C language variable assignment
- Rviz global status is displayed as the problem resolution of error
- [debug notes] pointer error when STD:: vector is used in VTK “access conflict when reading location XXX”
- Vue element admin configure global styles
- Maven global configuration
- Python UnboundLocalError: local variable ‘num’ referenced before assignment
- Unity “Feature `out variable declaration’ cannot be used because it is not part of the C# 4.0” error
- AWS appasync error global.TYPE.xx
- ASP.NET Parser Error Message: Could not load type ‘Web.Global’.
- Error in the latest version of ffmpeg: ‘codec’_ FLAG_ GLOBAL_ Header ‘undeclared identifier solution
- Solving Python error: local variable ‘a’ referenced before assignment
- Resolution of problems with rviz global status displayed as error
- Caused by the “error string in namespace std does not name a type” error
- [error] OpenEvent(“Global\ngx_reload_11812“) failed (2: The system cannot find the file specified
- How to read JS file app.ux Global variables in