extern
关键字主要用来声明变量extern double pi; // ok: declaration not definition
便可使用extern也同时初始化code
extern double pi = 3.1416; // definition
定义后声明能够,但声明后再定义不行it
//能够 extern double pi = 3.1416; // definition extern double pi; // ok: declaration not definition //失败 extern int a; extern int a = 1;
定义一个const
全局变量,默认不能够被extern
, 想要在其余文件使用的话,必须定义为extern
const变量(常量)定义时必须初始化io
//file a.cpp extern const int Path = 1024; //file b.cpp extern const int Path;