Let’s say we have:
class Base {...}
class A : public Base {...}
class B : public Base {...}
Is it possible to set as argument type of a generic method:
myMethod([typei'mlookingfor] c) {}
so that I can pass Base, A and B to myMethod() without overloading the method?
and also make it work with references and pointers?
If a pointer or a reference to the base class works for you, just use that:
Note that you’ll have to use references or pointers to prevent object slicing. If the method is
myMethod(Base c), you’ll lose type information of derived objects.If not, you can use a template