In the following code
#include
using namespace std;
class A {
public:
A() {}
virtual ~A() {};
};
class B : public A {
public:
void process(const A&);
is a better (exact) match, since dereferencing A*
gives you A&
.
Short answer, but there isn't much more to say unless you want a reference from the standard.
You could dynamic_cast
the result of *a
and that would give you a B&
, but that's smelly desing. What you probably want is a virtual function in A
that's overriden in B
(assume it's called foo
). Then, calling a->foo()
would dispatch to B::foo
.