specialized templates....hmm

look at this:

#include <iostream>
using namespace std;

struct strT
{
int n;
int n2;
};

template<typename T>
void swap(T&,T&);

void swap(strT&,strT&);

template <> void swap(strT&,strT&);

void main()
{
strT workT = {10,100};
strT workT2 = {100,1000};
int a=66;
int b=44;
swap(a,b);

}

template<typename T>
void swap(T &n1,T &n2)
{
T temp = n1;
n1=n2;
n2=temp;
}

void swap(strT& t1,strT& t2)
{
strT tempStructstrT = t1;
t1 = t2;
t2 = tempStructstrT;
}
template <> void swap(strT &t1,strT &t2)
{
int strTtemp = t1.n;
t1.n = t2.n;
t2.n = strTtemp;
strTtemp = t1.n2;
t1.n2 = t2.n2;
t2.n2 = strTtemp;
}

now this time i really dont see any reason to get any error...but i get this error:
d:\Programming\C++\Code\Draft\main.cpp(23) : error C2668: 'swap' : ambiguous call to overloaded function
d:\Programming\C++\Code\Draft\main.cpp(11): could be 'void swap<int>(T &,T &)'
with
[
T=int
]
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\utility(13): or 'void std::swap<int>(_Ty &,_Ty &)'
with
[
_Ty=int
]
while trying to match the argument list '(int, int)'

im practicing some templates...so as u see im kinda new to it...
10x in advance
[1623 byte] By [DevGuy] at [2007-11-19 6:28:26]
# 1 Re: specialized templates....hmm
problem solved!
the reason the error poped up was that 'swap' is an already defined class in cpp...(-: (vc++)
DevGuy at 2007-11-11 0:31:04 >
# 2 Re: specialized templates....hmm
problem solved!
the reason the error poped up was that 'swap' is an already defined class in cpp...(-: (vc++)
Actually, "swap" is declared in the 'std' namespace. If you remove "using namespace std;", it should also compile...

;)

Viggy
MrViggy at 2007-11-11 0:32:04 >