我不明白为什么error: no matching function for call to ‘Child::m(Mother&)在尝试编译代码时会出现此错误。
据我所知:由于 c 的类型是Child, Child::m 有一个类型参数,Child而 m 是Motherin类型,c.m(m)那么需要调用来自 Mother 类的函数 m() 。
class Mother{
public:
void m(const Mother&) {
}
};
class Child: public Mother{
public:
void m(const Child&) {
}
};
int main() {
Mother m;
Child c;
c.m(m);
}
Run Code Online (Sandbox Code Playgroud)