Re: [問題] 同一個function在不同cpp檔使用

看板C_and_CPP (C/C++)作者 (Alien)時間16年前 (2009/03/26 10:58), 編輯推噓0(001)
留言1則, 1人參與, 最新討論串3/3 (看更多)
※ 引述《gppo (香蕉是什麼?)》之銘言: : 我在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 超混亂的... 把東西重安安排好吧: ================= a.h: #ifndef __A_H__ #define __A_H__ void A(); #endif =================== a.cpp #include "a.h" void A() { .... }; ==================== 要是 x1 和 x2 沒有必要的話 (header 裡的東西 沒有涉及 a.h 的東西) , 就不要include a.h, 只是 implentation 用的話就放回在 x1.cpp 和 x2.cpp include a.h 就好. main.cpp 單純只放 main() 相關的東西就好了 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 202.155.236.82

03/26 13:43, , 1F
謝謝 我想我要重新安排一下function的放置了..
03/26 13:43, 1F
文章代碼(AID): #19okz1tS (C_and_CPP)
文章代碼(AID): #19okz1tS (C_and_CPP)