1 Star 0 Fork 2

codes_test/cpp-Interview2

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
using_global.cpp 680 Bytes
一键复制 编辑 原始数据 按行查看 历史
ericps 提交于 2022-03-31 22:31 +08:00 . upload code for friend, using and colon
//
// Created by pengshuai on 2022/3/31.
//
#include <iostream>
//#define isNs1 1
#define isGlobal 2
using namespace std;
void func()
{
cout<<"::func"<<endl;
}
namespace ns1 {
void func()
{
cout<<"ns1::func"<<endl;
}
}
namespace ns2 {
#ifdef isNs1
using ns1::func; /// ns1中的函数
#elif isGlobal
using ::func; /// 全局中的函数
#else
void func()
{
cout<<"other::func"<<endl;
}
#endif
}
int main()
{
/**
* 这就是为什么在c++中使用了cmath而不是math.h头文件
*/
// 会根据当前环境定义宏的不同来调用不同命名空间下的func()函数
ns2::func();
return 0;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/codes_test/cpp-interview2.git
git@gitee.com:codes_test/cpp-interview2.git
codes_test
cpp-interview2
cpp-Interview2
main

搜索帮助