作者phdch (我们都活在这个城市里面)
看板C_and_CPP
标题[问题] virtual function验证,不能执行
时间Thu May 7 01:54:32 2009
#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
1F:推 yoco315:你要不要重装一下你的 dev 05/07 01:59
2F:→ phdch:谢谢 1F的指教 确实是这样 05/07 03:00