/
githubmirror
/
CPlusPlusThings
Обзор
Документация
Войти
/
githubmirror
/
CPlusPlusThings
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
basic_content/using/using_global.cpp
35 строк
730 B
zhangxing
support bazel complie this project and format code.
30 мар 2024, 17:00
30 мар 2024, 17:00
3c8a3f2
Код
Авторство
О чём код?
/** * @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 ns1 namespace ns2 { #ifdef isNs1 using ns1::func; /// ns1中的函数 #elif isGlobal using ::func; /// 全局中的函数 #else void func() { cout << "other::func" << endl; } #endif } // namespace ns2 int main() { /** * 这就是为什么在c++中使用了cmath而不是math.h头文件 */ ns2::func(); // 会根据当前环境定义宏的不同来调用不同命名空间下的func()函数 return 0; }