Hi everybody, I'm a beginner in c++ and I have a problem with templates. When I compile this code in visual C++ 2008 i get an error:
error C2668: 'swap' : ambiguous call to overloaded function.
There is another function called swap in the std namespace (which actually does the exact same thing as yours), try rename your function to something else, it will work.
@webJose
If the template type can be gathered from the function parameters then you don't have to explicitly tell the complier the type, although you can and it's sometimes necessary as in this example:
1 2 3
float f = 0.5;
int i = 0;
std::max<float>(f,i);
If you don't specify the template type than the complier can't decide to call max<int> or max<float>.