命名空间的使用
在不同的命名空間中可以使用相同的變量名稱,
#include<iostream> using namespace std; namespace nconst {const int top = 1;const int bottom = 2;const int left = 3;const int right = 4; } namespace memo {const char* top = "1";const char* bottom = "2";const char* left = "3";const char* right = "4"; }int main() {int n;cin >> n;switch (n){case nconst::left:cout << memo::left << endl;case nconst::right:cout << memo::right << endl;case nconst::bottom:cout << memo::bottom << endl;case nconst::top:cout << memo::top << endl;default:break;}system("pause");return 0; }總結(jié)