【发布时间】:2020-04-18 04:51:06
【问题描述】:
我不明白为什么在尝试编译代码时出现此错误error: no matching function for call to ‘Child::m(Mother&)。
据我了解:
因为 c 的类型是 Child 并且 Child::m 有一个 Child 类型的参数,而 m 在 c.m(m) 中是 Mother 类型的,那么需要调用的是来自 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);
}
【问题讨论】:
标签: c++ debugging computer-science