Re: [問題] 同一個function在不同cpp檔使用
※ 引述《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
03/26 13:43, 1F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 3 之 3 篇):
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章