C ++中的外部变量错误 [英] Extern variable error in C++
本文介绍了C ++中的外部变量错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个变量
char buf_temp[10];
它是在a.cpp文件和b.cpp文件中全局定义的,我正在使用
It is defined global in a.cpp file and in b.cpp i am using
extern char buf_temp[10];
但是当我编译代码时,我得到了错误:-
But when i compile the code i get and error that :-
b.obj : error LNK2005: "char * data" (?data@@3PADA) already defined in a.obj
为什么会这样?
Why is it so?
How to remove it?
推荐答案
buf_temp
可能不是您的问题,链接器报告了char * data
的多个实例.
最好的问候
Espen Harlinn
buf_temp
is probably not your problem, the linker is reporting multiple instances ofchar * data
.
Best regards
Espen Harlinn
应该可以.确保将定义char buf_temp[10]
放入a.cpp并将extern
声明放入a.h.然后,在使用这些内容的所有地方都应添加a.h.
That should work fine. Make sure you put the definitionchar buf_temp[10]
into a.cpp and put theextern
declaration to a.h. Then you should include a.h everywhere you use the stuff.
这篇关于C ++中的外部变量错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文