Hello, I have some question:
template<class T>
void swap(T* a, T* b) {
T temp = *a;
*a = *b;
*b = temp;
}
int x,y;
swap(&x,&y);
swap(x,y); //why this compile and it works?
template<class T>
void swap(T* a, T* b) {
T temp = *a;
*a = *b;
*b = temp;
}
int x,y;
swap(&x,&y);
swap(x,y); //why this compile and it works?
To copy to clipboard, switch view to plain text mode
template<class T>
void swap(T* a, T* b) {
T* temp = *a;
*a = *b;
*b = temp; // *b = *temp; /*with this same problem before */
}
int x,y;
swap(&x, &y); //why now this doens't compile?
swap(x, y); // why this compile
template<class T>
void swap(T* a, T* b) {
T* temp = *a;
*a = *b;
*b = temp; // *b = *temp; /*with this same problem before */
}
int x,y;
swap(&x, &y); //why now this doens't compile?
swap(x, y); // why this compile
To copy to clipboard, switch view to plain text mode
For what I knew, with void swap(T* a, T* b), should only work swap(&x, &y);
Thanks in advance.
Bookmarks