C++ abstract class parameter error workaround

Of course, change the signature:

void test(A& x)
//or
void test(const A& x)
//or
void test(A* x)

The reason your version doesn't work is because an object of type A doesn't logically make sense. It's abstract. Passing a reference or pointer goes around this because the actual type passed as parameter is not A, but an implementing class of A (derived concrete class).


Since you cannot instantiate an abstract class, passing one by value is almost certainly an error; you need to pass it by pointer or by reference:

void test(A& x) ...

or

void test(A* x) ...

Passing by value will result in object slicing, with is nearly guaranteed to have unexpected (in a bad way) consequences, so the compiler flags it as an error.