The assignment is simple: Write a function template with the following declaration:
Code:
template <class S>
void swap( S *a, S *b );
So, I wrote the easy little function like so:
Code:
template <class S>
void swap( S *a, S *b )
{
S temp = *a;
*a = *b;
*b = temp;
}
The problem is when I try to call it like so:
Code:
int a=1, b=2;
swap(a, b);
The compiler says that there's no matching function, swap(int&, int&). I did get the function to work if I called it like this:
That makes sense, I suppose, but it seems very inconveinent. I'm used to passing the arguments as reference parameters and then just calling it like swap(a, b).
Do I need to call the assigned function as swap(&a, &b) all the time, or is there something else I'm missing?