problem with templates please help.....
please help me with this ....
I can't seem to get my code work...
the following code doen't seem to work.
Here's the code.
#include<iostream>
using namespace std;
template <class T>
T swap(T &a , T &b)
{
T c ;
c = a;
a = b;
b = c;
}
int main()
{
int a = 1,b = 2;
float c = 1.0,d = 2.0;
char e = 'A',f = 'B';
swap(a,b);
swap(c,d);
swap(e,);
}
these are the errors I am receiving
template1.cpp: In function `int main()':
template1.cpp:22: error: call of overloaded `swap(int&, int&)' is ambiguous
template1.cpp:8: error: candidates are: T swap(T&, T&) [with T = int]
/usr/include/c++/3.3.3/bits/stl_algobase.h:121: error: void
std::swap(_Tp&, _Tp&) [with _Tp = int]
template1.cpp:23: error: call of overloaded `swap(float&, float&)' is ambiguous
template1.cpp:8: error: candidates are: T swap(T&, T&) [with T = float]
/usr/include/c++/3.3.3/bits/stl_algobase.h:121: error: void
std::swap(_Tp&, _Tp&) [with _Tp = float]
template1.cpp:24: error: call of overloaded `swap(char&, char&)' is ambiguous
template1.cpp:8: error: candidates are: T swap(T&, T&) [with T = char]
/usr/include/c++/3.3.3/bits/stl_algobase.h:121: error: void
std::swap(_Tp&, _Tp&) [with _Tp = char]
Please Help.. I need to finish the chapter on templates as soon as possible
And by the way if u know any websites which would help me with C++ please specify
especially the one which would help to study C++ inside out............
Thanks
I hope you all will help
|