C++ overloading and overriding

Viewed 100

This code generates the following compilation error :

error: no matching function for call to 'C::print(int)'

can you help me figuring out the procedure that the compiler did to generate that error , (why it ignored the function in class B)

#include <iostream>
using std::cout;
class A {
public:
  virtual void print () 
   { cout << "A";}
};
class B : public A {
   int x;
 virtual void print (int y) 
   {cout << x+y;}
};

class C : public B {
public:
  void print ()
   {cout << "C";}
};

int main () {
  C* ptr = new C;
  ptr->print (5);
}
3 Answers
Related