2

I don't understand why I have this error error: no matching function for call to ‘Child::m(Mother&) when I try to compile my code.

From what I understand: since the type of c is Child and Child::m have a parameter of type Child while m is of type Mother in c.m(m) then it's the function m() from the Mother class who need to be called.

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);
}
Sydney.Ka
  • 175
  • 7

1 Answers1

5

Your Child class has no member function m that takes a Mother. It is hidden by the m declared in Child. You can unhide it by adding using Mother::m; in Child.

Jesper Juhl
  • 30,449
  • 3
  • 47
  • 70