问题
填空题
下列程序编译时发现pb->f(10);语句出现错误,其原因是______。 #include<iostream.h> class Base { public: void f(int x){cout<<"Base:"<<x<<endl;) }; class Derived:public Base { public: void f(char*str){cout<<"Derived:"<<str<<endl;} }; void main(void) { Derived*pd=new Derived; Pd->f(10); }
答案
参考答案:数据类型不匹配
解析: pd为派生类Derived的指针,指向派生类的成员函数f(char*Str),不指向基类的f(intx)。