我很奇怪,为什么下面的人为的例子代码在Visual Studio 2005中完全正常,但会产生在GCC错误(“没有匹配的函数来调用”呼叫插值时() 如下所示)。GCC 4.0:“没有匹配的函数来调用”模板功能
另外,我该如何解决这个问题?看来,错误消息只是一个通用消息,因为GCC没有针对问题的实际原因提供更具体的消息,并且它必须输出一些内容。对于如何在没有一些非常丑陋的解决方法的情况下继续移植这个类,我有点不知所措。
namespace Geo
{
template <class T>
class TMyPointTemplate
{
T X,Y;
public:
inline TMyPointTemplate(): X(0), Y(0) {}
inline TMyPointTemplate(T _X,T _Y): X(_X), Y(_Y) {}
inline T GetX()const { return X; }
inline T GetY()const { return Y; }
//...
template<T> TMyPointTemplate<T> Interpolate(const TMyPointTemplate<T> &OtherPoint)const
{
return TMyPointTemplate((X+OtherPoint.GetX())/2,(Y+OtherPoint.GetY())/2);
}
};
typedef TMyPointTemplate<int> IntegerPoint;
}
Geo::IntegerPoint Point1(0,0);
Geo::IntegerPoint Point2(10,10);
Geo::IntegerPoint Point3=Point1.Interpolate(Point2); //GCC PRODUCES ERROR: no matching function for call to 'Geo::TMyPointTemplate<int>::Interpolate(Geo::IntegerPoint&)'
感谢您的帮助,
阿德里安
优秀的答案。非常感谢你的帮助! :-) – 2009-02-03 16:20:05