hkBattousai
hkBattousai

Reputation: 10931

Implementing and calling a static method in a template class

My code is as below:

Interpolation.h

#ifndef INTERPOLATOR
#define INTERPOLATOR

#include <vector>
#include <utility>

template <class T>
class Interpolator
{
    public:
        static T InterpolateVector(const std::vector<std::pair<T, T>> & Vector, T At);

    private:
        static T GetBasisValue(T x);
};

template <class T>
T Interpolator::InterpolateVector(const std::vector<std::pair<T, T>> & Vector, T At) // Line #22
{
    // ...
}   // Line #25

// ...

#endif  // INTERPOLATOR

main.cpp

#include <vector>
#include <utility>
#include "Interpolator.h"

int wmain(int argc, wchar_t *argv[])
{
    std::vector<std::pair<float, float>> Measurements;
    Measurements.push_back(std::make_pair(0, 80.8));
    Measurements.push_back(std::make_pair(1, 80.4));
    Measurements.push_back(std::make_pair(3, 80.1));
    Measurements.push_back(std::make_pair(4, 79.6));

    float y2 = Interpolator<float>::InterpolateVector(Measurements, 2.0f);

    return 0;
}

When I build this code, I get the following error messages:

C:...\Interpolator.h; Line #22
error C2955: 'Interpolator' : use of class template requires template argument list

C:...\Interpolator.h; Line #25
error C2244: 'Interpolator::InterpolateVector' : unable to match function definition to an existing declaration

Can anyone please tell me what I am doing wrong here?

(IDE: Visual Studio 2010 Ultimate)

Upvotes: 1

Views: 6585

Answers (2)

user2100815
user2100815

Reputation:

#ifndef INTERPOLATOR
#define INTERPOLATOR

#include <vector>
#include <utility>

template <class T>
class Interpolator
{
    public:
        static T InterpolateVector(const std::vector<std::pair<T, T> > & Vector, T At);

    private:
        static T GetBasisValue(T x);
};

template <class T>
T Interpolator <T> ::InterpolateVector(const std::vector<std::pair<T, T> > & Vector, T At) // Line #22
{
    // ...
}   // Line #25

Upvotes: 1

Didier Trosset
Didier Trosset

Reputation: 37437

As written in the error message: 'Interpolator' : use of class template requires template argument list

You should write:

template <class T>
T Interpolator<T>::InterpolateVector(const std::vector<std::pair<T, T>> & Vector, T At) // Line #22
{
    // ...
}   // Line #25

Upvotes: 6

Related Questions