Commit aacaddcf authored by Administrator's avatar Administrator
Browse files

add namespace

parent fff4c471
#include <iostream>
using namespace std;
// 第一个命名空间
namespace first_space {
void func(){
cout << "Inside first_space" << endl;
}
}
// 第二个命名空间
namespace second_space {
void func(){
cout << "Inside second_space" << endl;
}
}
// 嵌套命名空间
namespace third_space {
void func() {
cout << "Inside third_space" << endl;
}
// 代码声明
namespace fourth_space {
void func() {
cout << "Inside fourth_space" << endl;
}
}
}
int main () {
// 调用第一个命名空间中的函数
first_space::func();
// 调用第二个命名空间中的函数
second_space::func();
// 调用第三个命名空间中的函数
third_space::func();
// 调用第四个命名空间中的函数
third_space::fourth_space::func();
// 制定使用特定的命名空间后,可以隐式调用方法
using namespace third_space::fourth_space;
// 隐式调用fourth_space中的func方法
func();
return 0;
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment