1. If a function template is defined:
template <typename A>
A SQ(A& a)
{
return a*a;
}
How could prevent users from passing a type which makes no sense, like
Employee class type?
2. If Employee is pass as T in the template below, should an assignment
operator have to be defined since there're assignment operation in the
function?
template <class T>
void swap(T& x, T& y)
{
T temp;
temp = x;
x = y;
y = temp;
}
3. Is "template <class T>" equivalent to "template <typename T>"?
Thanks!
template <typename A>
A SQ(A& a)
{
return a*a;
}
How could prevent users from passing a type which makes no sense, like
Employee class type?
2. If Employee is pass as T in the template below, should an assignment
operator have to be defined since there're assignment operation in the
function?
template <class T>
void swap(T& x, T& y)
{
T temp;
temp = x;
x = y;
y = temp;
}
3. Is "template <class T>" equivalent to "template <typename T>"?
Thanks!
Comment