Me pregunto por qué el siguiente código de ejemplo artificial funciona perfectamente en Visual Studio 2005, pero genera un error en GCC ("función no coincidente para llamar" al llamar a Interpolate() Como se muestra abajo).GCC 4.0: "función no coincidente para llamar" en la función de plantilla
Además, ¿cómo puedo solucionar esto? Parece que el mensaje de error es solo un mensaje genérico porque GCC no tenía un mensaje más específico por el motivo real del problema y tenía que generar algo. Estoy un poco perdido sobre cómo proceder portar esta clase sin algunas soluciones realmente desagradables.
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&)'
Gracias por su ayuda,
Adrian
Excelente respuesta. ¡Muchas gracias por tu ayuda! :-) –