[問題] virtual function驗證,不能執行

看板C_and_CPP (C/C++)作者 (我們都活在這個城市裡面)時間16年前 (2009/05/07 01:54), 編輯推噓1(101)
留言2則, 2人參與, 最新討論串1/1
#include<stdio.h> class Father { protected: int my_firstname(){return 100;} virtual int my_hand(){return 101;} public: int get_firstname(){return my_firstname();} int get_hand(){return my_hand();} }; class Kid:public Father { protected: int my_firstname(){return 200;}; virtual int my_hand(){return 201;}; }; int main() { int val1,val2,val3,val4; Kid kid; Father *ptr; val1=kid.get_firstname(); val2=kid.get_hand(); ptr=new Kid; val3=ptr->get_firstname(); val4=ptr->get_hand(); printf("val1=%d\n",val1); printf("val2=%d\n",val2); printf("val3=%d\n",val3); printf("val4=%d\n",val4); delete ptr; return 0; } DEV C++ compile結果是 line unit message ld C:\dev\ld cannot open crt2.o: No such file or directory. 好奇怪喔! debug不出來 不知道有沒有高手可以知道我哪裡出錯了? 還有城市中val1,val2,val3,val4四數的值為何? 太感激 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.137.82.147

05/07 01:59, , 1F
你要不要重裝一下你的 dev
05/07 01:59, 1F

05/07 03:00, , 2F
謝謝 1F的指教 確實是這樣
05/07 03:00, 2F
文章代碼(AID): #1A0SxPgO (C_and_CPP)
文章代碼(AID): #1A0SxPgO (C_and_CPP)