[問題] State Pattern

看板C_and_CPP (C/C++)作者 (累人啊....)時間14年前 (2012/03/13 12:32), 編輯推噓1(106)
留言7則, 2人參與, 最新討論串1/1
請看 http://ideone.com/IaLTR 對原有的模型作點變化(其實也是參考網路上其它人的code...) 但是錯誤訊息就滿怪的,不知道為什麼 (感覺有點像函數原型和函數定義那種感覺,只是現在遇到的是類別) 錯誤訊息如下 GState.h(20): E2315 'SetState' is not a member of 'GStateFlow', because the type is not yet defined E2303 Type name expected E2121 Function call missing ) GStateFlow.h(11): E2303 Type name expected E2034 Cannot convert 'int *' to 'GState *' E2379 Statement missing ; GStateFlow.h(14):E2315 'NextState' is not a member of 'GState', because the type is not yet defined 以下略,大致上都類似這樣的錯誤,請問我是忽略了哪個環節嗎? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 111.251.174.202

03/13 13:22, , 1F
把宣告(.h)和定義(.cpp)分開寫吧 你這樣寫定義會繞圈圈
03/13 13:22, 1F

03/13 13:50, , 2F
還真的可以....不過繞圈圈是什麼意思?
03/13 13:50, 2F

03/13 14:04, , 3F
我不知道這有什麼比較專業的術語XD 我的意思是GState
03/13 14:04, 3F

03/13 14:05, , 4F
和GStateFlow的定義會互相參考
03/13 14:05, 4F

03/13 14:06, , 5F
編譯GState時需要知道GStateFlow的介面,反之亦然
03/13 14:06, 5F

03/13 14:07, , 6F
所以可以把介面宣告抽離成.h檔,定義另外寫
03/13 14:07, 6F

03/13 15:04, , 7F
了改~~
03/13 15:04, 7F
文章代碼(AID): #1FNitpOz (C_and_CPP)
文章代碼(AID): #1FNitpOz (C_and_CPP)