1. 程式人生 > 其它 >理解:運算子

理解:運算子

技術標籤:C/C++程式設計c++

雙冒號::

用法1:類作用域

例如,申明函式

Human::setName(char* name);

用法2:名稱空間

std::cout << "Hello World" << std::endl;

用法3:全域性作用域,作用域全域性變數

#include <iostream>
using namespace std;
int amount=123; //全域性變數
int main()
{
int amount=456; //區域性變數
cout <<::amount <<endl; //輸出全域性變數
cout <<amount << endl;; //輸出區域性變數
::amount=789;
cout <<::amount << endl; //輸出全域性變數
cout <<amount << endl; //輸出區域性變數
return 0;
}