class A{
public:
A(){};
~A()();
void SetRect(CPoint c,boolean bCenter=TRUE);
void SetRect(CRect * pRect=NULL, boolean bRect=FALSE);
void SetRect(int16 x,int16 y,int16 dx=0,int16 dy=0,boolean bRect=FALSE);
};
以上定义了一个类和关于他的3个重载成员函数。
int main(int argc, char* argv[])
{
A a;
int nY = 90;
a.SetRect(0, nY);
return 0;
}
在代码中我写了和上述语句类似的语句,在VS2005下编译器告诉我:
error C2668: 'A::SetRect' : ambiguous call to overloaded function
could be 'void A::SetRect(int16,int16,int16,int16,boolean)'or 'void A::SetRect(CRect *,boolean)'while trying to match the argument list '(int, int)'
当我将上面语句换成
int main(int argc, char* argv[])
{
A a;
int nX = 0;
int nY = 90;
a.SetRect(nX, nY);
return 0;
}时就编译通过了。
编译器是怎么搞的呢,知道的请不吝赐教,谢谢了!~
------解决方案--------------------------------------------------------
ambiguous call to overloaded function,
编译器不知道你的a.SetRect(0, nY)对应的是 SetRect(CPoint c,boolean bCenter=TRUE)还是SetRect(CRect * pRect=NULL, boolean bRect=FALSE);
------解决方案--------------------------------------------------------
楼上正解