In the following code
#include
using namespace std;
class A {
public:
A() {}
virtual ~A() {};
};
class B : public A {
public:
You need to make process()
a virtual
member function of A
, B
:
class A {
public:
A() {}
virtual ~A() {};
virtual void process() const { cout << "processing A" << endl; }
};
class B : public A {
public:
B() {}
virtual ~B() {};
virtual void process() const override { cout << "processing B" << endl; }
};
int main(void) {
A* a = new B;
a->process();
return 0;
}
In your current code, *a
is of type A&
, so the closest match to process(*a);
is the first overload (for const A&
).