/
githubmirror
/
CPlusPlusThings
Обзор
Документация
Войти
/
githubmirror
/
CPlusPlusThings
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
english/basic_content/using/using_global.cpp
45 строк
754 B
xliu79
english
19 июл 2020, 05:38
19 июл 2020, 05:38
2bdeea8
Код
Авторство
О чём код?
/** * @file using_global.cpp * @brief using各种使用 * @author 光城 * @version v1 * @date 2019-08-07 */ #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头文件 */ ns2::func(); // 会根据当前环境定义宏的不同来调用不同命名空间下的func()函数 return 0; }