2.4-2

first_head.h
--------------------------------
#include<iostream>
using namespace std;

int a=10;//非const變量默認爲extern
//const int a=10;//error:在全局作用域聲明的const變量是定義該對象的文件的局部變量
                   此文件只存在於那個文件中,不能被其他文件訪問
extern const int b=10;//指定const變量爲extern,就可以在整個程序中訪問const對象

first.cpp
--------------------------------
int main()
{
 extern int a;
 cout<<a<<endl; //非const變量定義在一個文件中,可在另一個文件中使用這個變量
 cout<<b<<endl;


  system("pause");
}

發佈了22 篇原創文章 · 獲贊 1 · 訪問量 3064
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章