Ich versuche, eine Klassenmethode auf eine andere Klasse Methode Vorlage zu gehen und finden keine Antwort auf wie zu tun ist (ok keine 11 ++ C, steigern) :C++ vorbei Klassenmethode als Argument für eine Klassenmethode mit Vorlagen
ich das Kernproblem zu vereinfachen:
class Numerical_Integrator : public Generic Integrator{
template <class T>
void integrate(void (T::*f)()){
// f(); //already without calling f() i get error
}
}
class Behavior{
void toto(){};
void evolution(){
Numerical_Integrator my_integrator;
my_integrator->integrate(this->toto};
}
ich als Fehler angezeigt:
error: no matching function for call to ‘Numerical_Integrator::integrate(<unresolved overloaded function type>)’this->toto);
note: no known conversion for argument 1 from ‘<unresolved overloaded function type>’ to ‘void (Behavior::*)()’
Danke.
Bonus: Was ist mit den Argumenten?
class Numerical_Integrator{
template <class T, class Args>
double integrate(void (T::*f)(), double a, Args arg){
f(a, arg);
}
}
class Behavior{
double toto(double a, Foo foo){ return something to do};
void evolution(){
Foo foo;
Numerical_Integrator my_integrator;
my_integrator->integrate(this->toto, 5, foo};
}
[Boost-Funktion] (http://www.boost.org/doc/libs/1_61_0/doc/html/function.html) und [Boost-bind] (http://www.boost.org/doc/ libs/1_61_0/libs/bind/doc/html/bind.html)? Oder werfen Sie einen Blick auf die [Standard-Algorithmus-Bibliothek] (http://en.cppreference.com/w/cpp/algorithm) und sehen Sie, wie sie mit Prädikaten umgehen? –
Wozu brauchst du das T? Validierung? – thorsan
'f (a, arg);' <- müssen Sie auch das Objekt, das als 'this' in die Funktion wirkt. – coyotte508