定义非const变量时候,他是可以被其它文件访问的,(不用引入哪个文件)只需在使用的地方声明下,这个变量来之外部extern Type_Name Variable_Name。而const变量不能这样,默认的是文件的局部变量。若要改变这种情况则需特别声明 extern cconst int a;
/*
* const.cpp
*
* Created on: Nov 3, 2011
* Author: ubuntu
*/
extern const int a = 78;
//如果a不声明为extern,则不能在test.cpp中不通过引入文件就访问不到他。
int b=99;
#include<iostream>
//#include"const.cpp"
using namespace std;
int main()
{
extern int b;
extern const int a;
cout << a +9<< endl;
cout << b +89<< endl;
return 0;
}