c++ - 在 C++ 中混合重写和重载

标签 c++ debugging computer-science

我不明白为什么会出现此错误 error: no matching function for call to ‘Child::m(Mother&)当我尝试编译我的代码时。

据我了解: 因为 c 的类型是 Child和 Child::m 有一个类型为 Child 的参数而 m 的类型为 Motherc.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);
}

最佳答案

您的Child类没有采用Mother的成员函数m。它被 Child 中声明的 m 隐藏。您可以通过在 Child 中添加 using Mother::m; 来取消隐藏它。

关于c++ - 在 C++ 中混合重写和重载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59513933/

相关文章:

c++ - 在 C++ 程序中使用 ANTLR3

c++ - 如何使用#error 指令为用户提供指向有用信息的指针?

c# - .NET 基于 Web 的对象浏览器/检查器

algorithm - 在哪些现实场景中语义数据库比关系数据库更好?

c++ - XCB 错误 : 148 - Qt application display issues

c++ - 使用 std::shared_ptr 在生产者/消费者线程之间共享数据

c++ - 调试断言失败

debugging - 想法 : Debugger skipping lines

neural-network - "break symmetry"是什么意思?在神经网络编程的背景下?

java - 打印右对齐三角形