glovar.h 文件
#pragma once
static int glo;
one.h 文件
void getone();
one.cpp 文件
#include "stdafx.h"
#include "glovar.h"
#include "one.h"
void getone()
{
glo = 13;
printf("one: glo is %d \n",glo);
}
two.h 文件
void gettwo();
two.cpp 文件
#include "stdafx.h"
#include "glovar.h"
#include "one.h"
#include "two.h"
void gettwo()
{
glo = 15;
getone();
printf("two: glo is %d \n",glo);
}
main.cpp 文件
#include "stdafx.h"
#include "one.h"
#include "two.h"
int _tmain(int argc, _TCHAR* argv[])
{
gettwo();
return 0;
}
运行结果:
one: glo is 13
two: glo is 15