问题
填空题
下列程序编译时发现pb->f(10);语句出现错误,其原因是 【12】 。
# include<iostream. h>
class Base
public:
void f(int x)cout<<"Base:"<<x<<endl;
;
class Derived: public Base
public:
void f(char * str)cout<<"Derivcd:"<<str<<endl;
;
void main(void)
Derived * pd=new Derived;
pd->f(10)
答案
参考答案:数据类型不匹配
解析: 派生类中的成员函数隐藏了基类的同名函数,而参数10又无法隐式转换为char类型参数。