指针的迷惑
#include<iostream>#include<string>
#include<iomanip>
using namespace std;
class teacher{
public:
virtual void hello(){cout<<"hello ,I sorry to you"<<endl;}
~teacher(){}
};
class mathteacher:public teacher{
public:
virtual void hello(){cout<<"hello, l love you"<<endl;}
};
int main()
{
teacher *p=&mathteacher();
p->hello();
mathteacher *pp;
pp->hello();
return 0;
}
为什么只能输出"hello,I sorry to you"
但编辑器却能通过,我用的编辑器是C-Free3.5
如果我想用指针输出"hello,I sorry to you"
"hello,I love you"
怎样才能做到?
[此贴子已经被作者于2006-2-24 17:14:59编辑过]