C++ 命名空间
定义命名空间
#include <string>using namespace std;// 定义命名空间namespace Jack{ double pail; int pal; struct Well{ int name; int age; };}namespace Jill{ double fetch; struct Hill{ string name; int age; };}// 创建命名空间的别名namespace J = Jill;// 创建未命名的命名空间namespace { int ice; int bandycoot;}
命名空间的使用
#include <iostream>#include <cmath>int main() { using namespace std; std::cout << "Hello, World!" << std::endl; cout << "Hello, My Girls" << endl; double x = sqrt(9); cout << x; return 0;}double test(double i){ double x = sqrt(i); return x;}