PTT
Submit
Submit
選擇語言
正體中文
简体中文
PTT
C_and_CPP
[問題] 規劃、分割 class 與 header 架構
作者:
cory8249
(Cory)
2014-05-11 21:24:35
問題(Question):
請問如何正確規劃、分割 class 與 header 架構 ?
小弟目前寫一個 CPU 模擬器
開了以下幾個 class :
Core, Instruction, Memory, Regsiter, ALU, Controller
不曉得怎麼檔案架構分割比較好
想請教板上各位高手
首先 Core 是最大的一個 class 內部包含 Instruction , Memory ... 等等
而 ALU , Controller 又需要存取 Instruction , Memory, Register
1.
那這樣在 Core.h 的 class Core 宣告中 要用 forward declaration 嗎 ?
例如:
class ALU;
class Controller;
class Memory;
class ...
class Core{
public:
....
private:
Memory *imem, *dmem; // OK
ALU alu; // compile error : field alu has incomplete type
Controller controller; // compile error : field ... has incomplete type
};
forward delclaration 似乎只能用 pointer 的方式 ?
所以在 Core 裡面包含的其他 class 看似都要用 pointer 囉 ?
2.
因為有很多訊號、指令等等 我想開 enum 去寫
但是 enum 好像只能宣告定義一次而已
假設我在 Instruction.h 中定義了 enum InstType { R_TYPE, I_TYPE, J_TYPE };
但是 ALU 、 Controller 中也需要用到這個 enum
所以 ALU 、 Controller 要 #include "Instruction.h" ?
3.
因為 ALU , Controller 會互相存取資料、 call function 等等
Header include 要怎麼寫比較好 ?
可以互設為 friend class 嗎 ?
class ALU;
class Controller{
public:
friend class ALU;
private:
...
}
像是這樣 ?
問題有點多 不好意思 麻煩各位了 感謝
作者:
cory8249
(Cory)
2014-05-11 21:35:00
剛剛看到一篇不錯的:
http://goo.gl/eKQkGh
作者:
damody
(天亮damody)
2014-05-11 23:05:00
你的問題不適合斷行
作者:
plover
(喜歡你 ( ̄▽ ̄#)﹏﹏)
2014-05-14 10:27:00
" target="_blank" rel="nofollow">
或許可以參考
作者:
damody
(天亮damody)
2014-05-14 12:12:00
http://www.openemulation.com/
繼續閱讀
[問題] 讀多位數的數字 c語言
solinari
[問題] 字串轉數字不須判別正負?
putumaxally
[問題] openCV webcam即時影像處理
Klauspan
[問題] ffmpeg avi convert to mp4
willy01
[問題] 想請問c++有像c#可以矩陣擴增的語法嗎
kkinyao666
[問題] 清空字元陣列
brilliantye
[問題] 找不到project1.exe
si87118
[問題] 關於C99 6.3.1.8 Usual arithmetic conve
csosmo
[問題] 擷取binary字串
xit365025
Re: [問題] 讀檔問題 c語言
solinari
Links
booklink
Contact Us: admin [ a t ] ucptt.com