I have to classes :
template <class T>
class shared_vector
{
T data;
}
template <class T>
class device_vector
{
T data;
}
I want to write a function f which accects any kind of object, be it of type shared_vector
or device_vector
and sets some flags accordingly.
Now the obvious solution is to go for function overloading. But suppose the function f takes 10 arguments which can either be of shared_vector
or device_vector
,
I would have to write 1024 overloaded functions.
Another solution is to use a parent class hybrid_vector
from which both the device_vector
and shared_vector
inherit from.
But unfortunately, device_vector code is not in my control.
How should i solve this problem ?
NOTE : I know typeid (variable).name () can tell the type, but what will be my function declaration and how can I infer type from it ?