作者trancewu (exile me)
看板EE_DSnP
標題[問題] 請問new返回類型
時間Tue Apr 8 21:12:30 2008
new所返回的pointer是derived type還是base type?
new QuitCmd作為regCmd的參數,
不過regCmd需要的參數是CmdExec*,
這樣是說傳進去因為需要CmdExec*,
所以會自動把QuitCmd* resolve 成CmdExec*嗎?
謝謝。
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.4.234
※ 編輯: trancewu 來自: 140.112.4.234 (04/08 21:13)
1F:推 timrau:返回指定的type. 但是derived class "is a" base class 04/08 21:15
2F:→ timrau:所以把QuitCmd*當成CmdExec*來用是合法的 04/08 21:15
3F:→ trancewu:GOT IT 04/08 21:16
4F:→ trancewu:THANKS 04/08 21:16
5F:推 spock:我想請問一下,這是因為這些是 virtual drived class 的關係 04/08 22:55
6F:→ spock:還是只要是繼承的 class 都算? 04/08 23:00
7F:推 ric2k1:只要是繼承都可以. For the same reason: P* p = new C; 04/08 23:53
8F:→ ric2k1:return 就是對 caller 作一個 assign 的動作... 04/08 23:54