引用 3 楼 cfvmario 的回复: 例如这样 sample.h C/C++ code?1234#ifndef __SAMPLE_H_#define __SAMPLE_H_extern int a;#endif sample.c C/C++ code?1int a=0; 如果在头文件里面定义的是函数呢?
#ifndef __SAMPLE_H_ #define __SAMPLE_H_ int func(int a); #endif
#include "sample.h" int func(int a) { return a+1; }
.h里不要放定义,只放声明,再搞个对应的.c去定义
例如这样 sample.h C/C++ code?1234#ifndef __SAMPLE_H_#define __SAMPLE_H_extern int a;#endif sample.c C/C++ code?1int a=0;
#ifndef __SAMPLE_H_ #define __SAMPLE_H_ extern int a; #endif
int a=0;
70,024
社区成员
243,263
社区内容
加载中
试试用AI创作助手写篇文章吧