#include<iostream>
#include<string>
namespace china {
float population =14; //單位/億
std::string capital="北京";}
namespace japan {
float population =3.71; //單位/億
std::string capital="東京";}
using china::population;
using namespace std;
int main(void) {
cout<<population<<endl;
std::cout<<china::capital<<std::endl;
std::cout<<japan::capital<<std::endl;
cout<<japan::population<<endl;
system("pause");
return 0;
}
namespace china {
float population =14; //單位/億
std::string capital="北京";} 因為是定義命名空間所以大括號不需要在分號外面
命名空間的主要作用是為了區分兩個相同的變數,常量,通俗易懂的講班上有兩個相同名字的同學,為了區分開來分別取一個外號或者叫小名。命名空間就是起這樣的作用。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/30848.html
標籤:基礎類
上一篇:bcb老粉熬夜嘗鮮Qt和C#
