C++中如何定义全局静态变量,并可在多文件中通用,修改等

如题所述

第1个回答  2012-12-18
写一个头文件,my.h
内容:
#ifndef __MY_H__
#define __MY_H__
int my_v;
#endif
你愿意 用 const 也可以,但一旦有值,不能修改。
在要用的文件里用#include "my.h" 插入。
第2个回答  2012-12-19
  const 关键字用于修改字段或局部变量的声明。 它指定字段或局部变量的值是常数,不能被修改。 extern [const] [int|float|double|、、、、] a;
第3个回答  2012-12-18
1.cpp
extern const int a=100;
2.cpp
extern const int a;本回答被网友采纳
相似回答
大家正在搜