Reputation: 141
Is there a way to use same template function for performing operation on int and std::string, eg:
template<typename T>
T add(typename a, typename b)
{
return (a+b); // incase for int
return a.append(b); // incase for std::string
}
Any help is appreciated.
Upvotes: 0
Views: 114
Reputation: 8490
std::string supports the operator+.
concatenates two strings or a string and a char
template<typemane T>
T add(typename a, typename b)
{
return a + b;
}
Upvotes: 1