Reputation: 329
I try to figure out what is difference between this to function.
First one is template function for adding to expression :
template <class T,class Y,class Z>
Z add(T t,Y y)
{
return t+y;
}
Specialization_1 :
template<>
int add<int,int,int>(int t,int y)
{
return t+y+10000;
}
Specialization_2 :
int add(int t,int y)
{
return t+y+10000;
}
What difference is between speciaization_1 and specialization_2 ? Is it necessary to use template<> before declaration????
Upvotes: 0
Views: 61
Reputation: 386
the first is Specialization. the second is overloading.
the first will create a special varient of the template. and the second will create another function with the same name
Upvotes: 2
Reputation: 1687
I don't see interest in your first specialization. this is more useful for example:
template <typename T>
T add(T t,T y)
{
return t+y+10000;
}
Now you can use this function add for many differents type.
Upvotes: 0