函数重载没有最佳匹配问题 谢谢大家帮忙
我列出了几行关键的程序代码,程序在VC++6.0编译会出现这个问题,但是在visual studio 2010就不会有问题,不知道为什么?
cdouble tempRC, tempC, tempKineticC;
tempRC = tempR * exp(II * alpha/1000.);
for(int mR = 0; mR < nBasisRto; mR++)
{
for(int nBR = 0; nBR < nBandR; nBR++)
{
int nR = math.MOP.BandIB2NormalIJ(mR,nBR,nBandR);
if(nR < 0)
continue;
double basis = tempW * BasisR[mR + 1] * BasisR[nR + 1];
// overlap part 重叠积分
// Br*Br
OverlapR(mR,nBR) += basis;
//============= 1/2*Br'*Br' R动能
tempC = 0.5 * tempW * DeriveR[mR + 1] * DeriveR[nR + 1] * exp(-II * 2.0 * alpha/1000.);//II-1
// Coulomb potential
KineticCoulombR(mR,nBR) += tempC - 1.0 / tempRC * basis;
//============== 1/(2*r^2)*Br*Br 角动量
AngularR(mR,nBR) += 1.0 / SQR(tempRC) * basis;//如果你用友元的形式重载运算符的时候就要注意了 在VC++ 编译器(没有打sp6补丁)是必须有提前声明才行的
//
// tempC = -1.0*(1-exp(-POW(tempR/r0,3.0)))/ SQR(tempR) * BasisR[mR + nBasisR_from] * BasisR[nR + nBasisR_from];
// AngularRF(mR,nBR) += tempW * tempC;
//============== 1/8*B^2*(r^2-x^2): r^2*Br*Br
DiamagneticR(mR,nBR) += SQR(tempRC) * basis;
//============== F*x: F*r*cos(theta): r*Br*Br
ElectricR(mR,nBR) += tempRC * basis;
//dipole vs. electron: d*cos(theta)/R^2;
// ElectricRR(mR,nBR) += -polarizability * (1 - exp(-POW(tempR / r0, 6.0))) * SQR(tempR) / POW(SQR(tempR) + SQR(r0),2.0) * basis;
//ElectricRR(mR,nBR) += -polarizability * 1.0 / POW(tempR,4.0) * basis;
}
}
}
上面SQR函数是我一个constant.h头文件中定义的
typedef complex<int> cint;
typedef complex<float> cfloat;
typedef complex<double> cdouble;
//
const cdouble II(complex < double > (0, 1));
const cdouble IR(complex < double > (1, 0));
template<class T> T SQR(const T a)
{
return (a==0)?0:a * a;
}
template<class T> complex<T>
SQR (const complex<T> a)
{
return (a == CZERO) ? CZERO : a * a;
}
F:\桌面的东西\刘红平老师给的资料\linux.cpp(413) : error C2667: 'SQR' : none of 2 overload have a best conversion
F:\桌面的东西\刘红平老师给的资料\linux.cpp(413) : error C2668: 'SQR' : ambiguous call to overloaded function
F:\桌面的东西\刘红平老师给的资料\linux.cpp(419) : error C2667: 'SQR' : none of 2 overload have a best conversion
F:\桌面的东西\刘红平老师给的资料\linux.cpp(419) : error C2668: 'SQR' : ambiguous call to overloaded function
执行 cl.exe 时出错.