For a recent project, we need to port the code from VC to G ++ for compilation. In this process, we encountered several platform-related problems-the Code Compiled smoothly under VC, however, an error is reported during compilation in G ++.
Here we will share it with you:
1. Enumeration type issue code
enum MyWeek{ Monday, Tuesday,};MyWeek mw = MyWeek::Monday;
VC
D: \ Vc \ main. cpp (17): Warning c4482: non-standard extension used: the enumerated "myweek" is used in the qualified name"
G ++
main.cpp:11:14: error: ‘MyWeek’ is not a class or namespace MyWeek mw = MyWeek::Monday; ^
Summary
Myweek: Monday is not a C ++ standard, so avoid this method as much as possible. We recommend that you add a prefix of the enumeration type to the command enumeration to avoid repeated enumeration names. For example
enum MyWeek{ MW_Monday, MW_Tuesday,};
2. STD: Map: cbegin () problem code
std::map<int, int>::const_iterator cIter = testMap.cbegin();
VC
Compiled successfully
G ++
main.cpp:7:53: error: ‘class std::map<int, int>’ has no member named ‘cbegin’ std::map<int, int>::const_iterator cIter = testMap.cbegin(); ^
Summary
The result is run in G ++ 4.8.2, indicating that in G ++, there are no methods such as map: cbegin, MAP: Cend.
3. # include <map>
If there are spaces in the include header file, there is no problem in VC, but an error will be reported in G ++.
Main. cpp: 2: 16: Fatal error: Map: No file or directory # include <map> ^ compilation terminated.
From VC to G ++