templated Funktionszeiger
Ich habe einen Ansatz zum Aufrufen der verzögerten Funktion für die Klasse:
//in MyClass declaration:
typedef void (MyClass::*IntFunc) (int value);
void DelayedFunction (IntFunc func, int value, float time);
class TFunctorInt
{
public:
TFunctorInt (MyClass* o, IntFunc f, int v) : obj (o), func (f), value (v) {}
virtual void operator()();
protected:
MyClass* obj;
IntFunc func;
int value;
};
//in MyClass.cpp file:
void MyClass::DelayedFunction (IntFunc func, int value, float time)
{
TFunctorBase* functor = new TFunctorInt (this, func, value);
DelayedFunctions.push_back (TDelayedFunction (functor, time)); // will be called in future
}
void MyClass::TFunctorInt::operator()()
{
((*obj).*(func)) (value);
}
Ich möchte templated functor machen. Und das erste Problem ist, dass:
template <typename T>
typedef void (MyClass::*TFunc<T>) (T param);
Verursacht Compilerfehler: "Template-Deklaration von 'typedef'". Was kann eine Lösung sein?
PS: Der Code basiert aufhttp: //www.coffeedev.net/c++-faq-lite/en/pointers-to-members.html#faq-33.