I want to declare a vector in my .h file but depending on the precision of the data I send in I might want the vector to be of type double or I might want it to be of type float.
//tolerances.h
class verySimple{
public:
verySimple();
~verySimple();
void processTolerances(std::vector<double or float> tolerances);
};
Could I get a quick lesson, please?
Thanks.
It isn’t entirely clear what you want to accomplish, but judging by your example you want a function that can accept either float or double vectors.
You can overload functions in C++:
Then the appropriate one will be called depending on the argument.
Or, you can make the function a template:
Or, if
verySimpleas a whole depends on the type:Which way to choose depends on the natures of
verySimpleandprocessTolerances– there’s no general “best solution”.