我的代碼如下:實現並調用模板類的靜態方法
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;
}
當我建立此代碼,我收到以下錯誤消息:
C:... \ Interpolator.h;線#22
錯誤C2955: '插值':使用類 模板需要模板參數列表C:\ Interpolator.h;線#25
錯誤C2244: 「插補:: InterpolateVector」: 無法函數定義匹配 現有的聲明
誰能告訴我什麼,我做錯了什麼?
(IDE:Visual Studio 2010的旗艦版)
它的工作。非常感謝。在代碼中一切都好嗎? – hkBattousai 2011-06-07 14:20:10