global variable usage question in C++# Programming - 葵花宝典
a*e
1 楼
Three files: head.h, f1.cc, f2.cc
in head.h
#ifndef head_h_
#define head_h_
static int value;
void my_function();
#endif
in f1.cc
#include "head.h"
int main(){
value=3;
my_function();
cout< }
in f2.cc
#include "head.h"
void my_function(){
value=5;
}
For succinct, I define the global variable in head file.
If I omit
in head.h
#ifndef head_h_
#define head_h_
static int value;
void my_function();
#endif
in f1.cc
#include "head.h"
int main(){
value=3;
my_function();
cout<
in f2.cc
#include "head.h"
void my_function(){
value=5;
}
For succinct, I define the global variable in head file.
If I omit