The assignment is simple: Write a function template with the following declaration:
So, I wrote the easy little function like so:Code:template <class S> void swap( S *a, S *b );
The problem is when I try to call it like so:Code:template <class S> void swap( S *a, S *b ) { S temp = *a; *a = *b; *b = temp; }
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:Code:int a=1, b=2; swap(a, b);
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).Code: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?



LinkBack URL
About LinkBacks


