I was just playing around with templates, and I encountered the following problem.
using a new standard headers i had the following:
I get the following error:Code:#include<iostream> #include"test.h" using namespace std; int main() { char ch; int x = 10; int y = 15; cout << "x before: " << x << "\t y before: " << y << endl; swap(x, y); cout << "x after: " << x << "\t y after: " << y << endl; cin.get(ch); return 0; } AND THE TEMPLATE HEADER CLASS IS AS FOLLOWING: template<class T> void swap(T& one, T& two) { T temp; temp = one; one = two; two = temp; return; }
c:\documents and settings\mm59\desktop\cis 113\test4\test4.cpp(14) : error C2667: 'swap' : none of 2 overload have a best conversion
c:\documents and settings\mm59\desktop\cis 113\test4\test4.cpp(14) : error C2668: 'swap' : ambiguous call to overloaded function
However, when I use the older type with the 'using' directive, as following then there's no errors and everything works fine:
#include<iostream.h>
#include"test.h"
Can anyone explain to me why such thing occurs??? I used Borland 5.0 and Microsoft Visual C++ 6.0 and same results on both.....hmmm....
Maybe I'm doing something wrong when it comes to the new standard and templates???
Thanks for all info in advance...
matheo917