作者adrianshum (Alien)
看板C_and_CPP
标题Re: [问题] 同一个function在不同cpp档使用
时间Thu Mar 26 10:58:08 2009
※ 引述《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
1F:→ gppo:谢谢 我想我要重新安排一下function的放置了.. 03/26 13:43