//a.h该文件内定义g_aa静态
#ifndef __A_H__
#define __A_H__
static int g_aa;
#endif
//aa.h
#ifndef __AA_H__
#define __AA_H__
void fun();
#endif
//aa.cpp
#include <stdio.h>
#include <stdlib.h>
#include "a.h"
void fun()
{
g_aa =2;
printf("addr=%x\n",&g_aa);
}
//bb.h
#ifndef __BB_H__
#define __BB_H__
void fun2();
#endif
//bb.cpp
#include <stdio.h>
#include <stdlib.h>
#include "a.h"
void fun2()
{
g_aa =3;
printf("22 addr=%x\n",&g_aa);
}
//main.cpp
#include <stdio.h>
#include <stdlib.h>
#include "aa.h"
#include "bb.h"
#include "a.h"
int main(int argc, char**argv)
{
fun();
fun2();
return 0;
}
运行结果是多个地址,显然是独立的
|