the following code will generate a C2825 error in VS2005Beta2 July:
#include "stdafx.h" #include <vector> #include <iostream> int _tmain(int argc, _TCHAR* argv[]) { int i = 3, j = 6; std::swap<int>(i, j); //C2825 //but use std::swap<> <i, j>; will be ok return 0; } |
I don't know why this , but who else can explain it to me
many thanks.

C2825 error ?
Cyber Wombat
yes, I just want to pass the template parameters explicited. but it will cause a error when #include <vector> ,
the following codes works well in the Version before VS2005 July,
#include <vector>
#include <iostream>
int _tmain(int argc, _TCHAR* argv[])
{
double i = 3, j = 6;
std::swap<double> (i, j); //C2528 when in VS 2005 July
return 0;
}
,
what cause this problem thanks.
ProfEclipse
and the reason of using swap<double>.. is that I just want to know what causes this problem :-)
Gohan
Indradeep
Gandalf_The_White
std::swap<>(i, j);
The empty "<>" lets the compiler know that it should only consider function templates but the fact that it is empty means that the regular type deduction process will occur.
Note: in this case it is unnecessary as the std namespace is reserved and the only swap functions in std are all template functions (or explicit specializations of template functions).
Labrego
Just do std::swap(i, j);
eXseraph
thanks a lot:)