だから私は抽象ボタンクラスを持っています:
class Button
{
public:
int x, y, width, height;
std::string label, text;
bool checkForClick(int mouseX, int mouseY);
virtual void click(int mouseX, int mouseY) =0;
virtual void draw(); //has a default implementation which can be overridden
};
テンプレートクラスにしたいサブクラス:
template <typename T>
class IncrementButton : public Button
{
public:
T& controlValue;
T increment;
T minVal, maxVal;
IncrementButton(T& controlValue) : controlValue(controlValue) {}
void click(int mouseX, int mouseY);
void draw();
};
オーバーライドされたメソッドは次のようになります。
template <typename T>
void IncrementButton<T>::click(int mouseX, int mouseY)
{
//do something with controlValue
}
template <typename T>
void IncrementButton<T>::draw()
{
//use value of controlValue
}
しかし、これはコンパイルされません。エラーが表示されます:
Error 1 error LNK2001: unresolved external symbol "public: virtual void __thiscall IncrementButton<float>::click(int,int)" (?click@?$IncrementButton@M@@UAEXHH@Z)
...そして draw() についても同じこと
何か案は?私はC ++に比較的慣れていないので、間違っている愚かなことがあるかもしれないと思っています。