Re: C++繼承的問題
※ 引述《sorryChen (陳揚和)》之銘言:
: 比如說有三個class ex: A: 卡車 B:車 C:交通工具
: A繼承B繼承C..
: C中有一個function叫行駛..有另一個function加速
: 行駛會call加速
: 現在我在A override 加速這個function....
: (沒有override行駛這個函數)..
: 當我在A call行駛時..理論上應該要會間接call到新override的加速阿
: 可是好像是call 到C中最原始的加速...
: 我有加virtual啦..但好像沒用..請問要如何用沒有overrided的老函數中
: call到新override的函數,還是一定要把行駛也overrided..
: 我是用visual C++啦
http://rafb.net/p/uIAsNd44.html
以上的code在Visual C++ 2005中的結果是
Base::drive
MostDerived::speedup
應該是你要的結果吧?
--
自High筆記(半荒廢)
http://legnaleurc.blogspot.com/
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 211.74.131.10
推
02/11 15:51, , 1F
02/11 15:51, 1F
討論串 (同標題文章)
Programming 近期熱門文章
PTT數位生活區 即時熱門文章