作者gppo (香蕉是什麽?)
看板C_and_CPP
标题[问题] 同一个function在不同cpp档使用
时间Wed Mar 25 22:48:14 2009
我在main.cpp写了一个function void A(void)
main.cpp
-----------------------------
#include "x1.h"
#include "x2.h"
int main(void)
{
.....
return 0;
}
void A(void)
{...}
然後在x1.h与x2.h里面有写到
extern void A(void);
因为想在x1.cpp与x2.cpp里面使用A这个function
但是compile以後有出现下面的warning
x2.h [Warning] redundant redeclaration of `void A(void)' in same scope
x1.h [Warning] previous declaration of `void A(void)'
请问该怎麽改写才不会有这个warning呢?
另外有砍掉compile後产生的*.o档 再执行compile的话
会与没有砍掉*.o档直接compile的结果不同
这是怎麽回事呢?
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.116.187.104
1F:推 QQ29:function 预设就是extern了 03/25 23:03
2F:推 QQ29:我是看14161的@@ 03/25 23:05
3F:→ gppo:= =a 但是如果我把x1.h x2.h里面的extern那行砍掉 03/25 23:42
4F:→ gppo:他会说undeclared... 03/25 23:43
5F:推 sunneo:把A的标头档用#pragma once保护 03/25 23:48
6F:推 QQ29:gppo你好 你是说 把extern 修饰字拿掉 就坏? 03/26 00:20
7F:→ QQ29:你应该是整航拿掉吧 不能整航拿掉阿 至少要有宣告 才认的到 03/26 00:21
8F:→ gppo:QQ29你好 我把extern修饰字拿掉後 会一样是redundant... 03/26 13:32