How to use templates on this.
I have a handler class that handles all the class data (ie. Cars, Motors, Planes)
But I want to have a getData function which has a parameter that can identify which class to return.
Code:
class Handler
{
public:
Car *cars;
Motor *motors;
Plane *planes
Handler();
void getData(int index) // When index = 0; cars. 1 will be motors.
{
if(index == 0)
return cars;
else if(index ==1)
return motors;
};
So when I try to get the cars. I'll just call.
Handler->getData(0)->ViewData();
My problem is, how do I do that? I heard templates can do that but I don't know how to use it.