帮我看看c++代码。请教下问题

来源:百度知道 编辑:UC知道 时间:2024/05/24 04:09:06
#include <iostream>
using namespace std;

class n
{
int a,b;
public:
void get(){
cout<<"n"<<endl;
}
void put(){
cout<<"mkkkkkk"<<endl;
}
};

class m:public n
{
int c,d;
public:
void get(int a)
{
cout<<"m1"<<endl;
return 0;
}
};

int main()
{

m mm;
mm.get();

return 0;
}

为什么会有错,子类不能访问父类的get()。这是为什么?子类的get(int a)对他有什么影响啊。

子类的get函数与父类的get函数同名,而参数不同,所以隐藏了父类的get函数,因此通过子类不能再访问父类的get函数.
你的子类函数写错了,void函数没有返回值,
void get(int a)
{
cout<<"m1"<<endl;
return 0; //应该去掉
}