I’ve a lot of Java experience but new to C++.
I need to have a method, simple example is of set union, that will work with parameters of set<int> and of set<bool>, but no other types.
At the moment I have overloaded the method name, but it duplicates a lot of similar code in the method body.
Is there a better way? Thanks!
You can write a Function Template .
But you can do that if you are performing similar operations regardless of the type of arguments. If you are performing different operations for each of data types then you will have to specialize the template function which basically brings you back to your problem.