forked from Light-City/CPlusPlusThings
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusing_global.cpp
More file actions
Latest commit
45 lines (41 loc) · 754 Bytes
/
Copy pathusing_global.cpp
File metadata and controls
45 lines (41 loc) · 754 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/**
* @file using_global.cpp
* @brief using各种使用
* @author 光城
* @version v1
* @date 2019-08-07
*/
#include<iostream>
#defineisNs11
//#define isGlobal 2
usingnamespacestd;
voidfunc()
{
cout<<"::func"<<endl;
}
namespacens1 {
voidfunc()
{
cout<<"ns1::func"<<endl;
}
}
namespacens2 {
#ifdef isNs1
using ns1::func; /// ns1中的函数
#elif isGlobal
using ::func; /// 全局中的函数
#else
voidfunc()
{
cout<<"other::func"<<endl;
}
#endif
}
intmain()
{
/**
* 这就是为什么在c++中使用了cmath而不是math.h头文件
*/
ns2::func(); // 会根据当前环境定义宏的不同来调用不同命名空间下的func()函数
return0;
}