GCC 4.0: "no matching function to call" in template function

I am wondering why the following code of a far-fetched example works fine in Visual Studio 2005, but it generates an error in GCC ("there is no corresponding function to call" when Interpolate () is called, as shown below).

Also, how do I get around this? It seems that the error message is just a general message because GCC did not have a more specific message about the actual cause of the problem, and it had to output something. I don't understand a bit how to continue porting this class without any ugly workarounds.

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&)'

Thank you for your help,

Adrian

+5
source share
2 answers

, , inline

TMyPointTemplate Interpolate(const TMyPointTemplate &OtherPoint)const {

.

, , , .

template<class T> // <- here
TMyPointTemplate<T> TMyPointTemplate<T>::Interpolate(const TMyPointTemplate<T> &OtherPoint)const {
+9

Evan answer , , , .

, Interpolate - -- non ( , ). , :

template<T t> TMyPointTemplate<T> Interpolate
      (const TMyPointTemplate<T> &OtherPoint)const

, , 't':

Geo::IntegerPoint Point3=Point1.Interpolate <0> (Point2);

typename 'T' , . , "T" . -:

template <class T>
class TMyPointTemplate
{
public:
  //...
  template<class S> TMyPointTemplate<T> Interpolate
                 (const TMyPointTemplate<S> &OtherPoint) const
  {
    return ...;
  }                       
};
+9

All Articles