日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > c/c++ >内容正文

c/c++

[C++] 用Xcode来写C++程序[6] Name visibility

發布時間:2024/4/15 c/c++ 42 豆豆
生活随笔 收集整理的這篇文章主要介紹了 [C++] 用Xcode来写C++程序[6] Name visibility 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

用Xcode來寫C++程序[6] Name visibility

?

此小結包括了命名空間的一些使用細節

?

命名空間

#include <iostream> using namespace std;namespace foo {// 函數int value() {return 5;} }namespace bar {// 常量const double pi = 3.1416;// 函數double value() {return 2*pi;} }int main () {cout << foo::value() << '\n';cout << bar::value() << '\n';cout << bar::pi << '\n';return 0; }

打印結果

5 6.2832 3.1416 Program ended with exit code: 0

?

?

?

使用命名空間

#include <iostream> using namespace std;namespace first {int x = 5;int y = 10; }namespace second {double x = 3.1416;double y = 2.7183; }int main () {// 聲明使用命名空間中的某個元素using first::x;using second::y;cout << x << '\n';cout << y << '\n';// 直接使用命名空間中的某個元素cout << first::y << '\n';cout << second::x << '\n';return 0; }

打印結果

5 2.7183 10 3.1416 Program ended with exit code: 0

?

#include <iostream> using namespace std;namespace first {int x = 5;int y = 10; }namespace second {double x = 3.1416;double y = 2.7183; }int main () {// 聲明使用命名空間first中的元素using namespace first;cout << x << '\n';cout << y << '\n';// 使用命名空間second中的元素cout << second::x << '\n';cout << second::y << '\n';return 0; }

打印結果

5 2.7183 10 3.1416 Program ended with exit code: 0

?

#include <iostream> using namespace std;namespace first {int x = 5; }namespace second {double x = 3.1416; }int main () {// 使用命名空間first {using namespace first;cout << x << '\n';}// 使用命名空間second {using namespace second;cout << x << '\n';}return 0; }

打印結果

5 3.1416 Program ended with exit code: 0

?

總結

以上是生活随笔為你收集整理的[C++] 用Xcode来写C++程序[6] Name visibility的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。