Your function will compile only if there is an implicit conversion from int to T If this is your intention, everything is in order, but in reality it is not very good.
I think it is better if you rewrite your code to return T , possibly using something like:
//return T(0); return static_cast<T>(0); // Better alternative as suggested by Steve Jessop
This explicitly builds a T from int. Keep in mind that if someone calls this method with T , which can build from int , it will work - no matter what this constructor really means.
source share