iT邦幫忙

2021 iThome 鐵人賽

DAY 14
0
自我挑戰組

少年DevOps的C++奇怪漂流系列 第 14

Day14

域解析運算子:: 真不知道該怎麼形容它螞蟻書也寫得很玄,不如直接看範例,在main()中print number會顯示10.5如果想要使用global number就必須使用::解析域運算元去指定現在要使用的命名空間,反正就是這樣。

// Fig. 6.23: fig06_23.cpp
// Using the unary scope resolution operator.
#include <iostream>
using std::cout;
using std::endl;

int number = 7; // global variable named number

int main()
{
   double number = 10.5; // local variable named number

   // display values of local and global variables
   cout << "Local double value of number = " << number
      << "\nGlobal int value of number = " << ::number << endl;
   return 0; // indicates successful termination
} // end main

void set_varible(){

   short number = 7

}


上一篇
Day13-stack
下一篇
Day15-Overloading
系列文
少年DevOps的C++奇怪漂流30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言