Hi,
I'm pretty new on C++ so maybe this is obvious to you.
I'm trying to compile this code with MSVC. This code is taken from a C++ book as an example using templates.
As I understand, the compiler is supposed to understand which code to produce from the type you send as arguments in the function call. In this case two int's.Code:#include <iostream> using namespace std; template <typename Any> void swap(Any &a, Any &b); int main() { cout.precision(2); cout.setf(ios::fixed, ios::floatfield); int i = 10, j = 20; cout << "i, j = " << i << ", " << j << ".\n"; swap(i, j); cout << "i, j = " << i << ", " << j << ".\n"; return 0; } template <typename Any> void swap(Any &a, Any &b) { Any temp; temp = a; a = b; b = temp; }
But I get two fault codes:
error C2667: 'swap' : none of 2 overload have a best conversion
error C2668: 'swap' : ambiguous call to overloaded function
Please, someone who can explain what this means?



LinkBack URL
About LinkBacks



