欢迎访问 生活随笔!

生活随笔

当前位置: 首页 >

命名空间的使用

发布时间:2025/4/16 28 豆豆
生活随笔 收集整理的这篇文章主要介绍了 命名空间的使用 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

在不同的命名空间中可以使用相同的变量名称,

#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; }

总结

以上是生活随笔为你收集整理的命名空间的使用的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。