Can someone please tell me which is the preferred way to write a template function based on the 2 examples supplied? Both of these compile and produce the same results, and I understand the differences between them, but is one better than the other? Thanks.
[SOURCE]
// TEMPLATE DECLARATION
template <typename tType>
const tType max(const tType & x, const tType & y);
// TEMPLATE IMPLEMENTATION
template <typename tType>
const tType max(const tType & x, const tType & y)
{
// IF x < y THEN USE y ELSE USE x
return x < y ? y : x;
}
[/SOURCE]
[SOURCE]
// TEMPLATE DECLARATION
template <typename tType>
tType const & max(tType const & x, tType const & y);
// TEMPLATE IMPLEMENTATION
template <typename tType>
tType const& max(tType const & x, tType const & y)
{
// IF x < y THEN USE y ELSE USE x
return x < y ? y : x;
}
[/SOURCE]