funktionsauswahl...etwas unschöner style...
-
hi leute!
zuerst mal bissi code:struct Struct1 { float (*InterpolateFn)(float, float, float); } float Interpolate1(float a,float b,float x) { return a*b*x; } float Interpolate2(float a,float b,float x) { return 2*a*2*b*2*x; } int main() { struct Struct1 Vars; Vars.InterpolateFn = Interpolate1; // funktion auswählen mit der man arbeiten will float i1 = Vars.InterpolateFn(v1 , v2 , frac_a); }
ich find den code etwas unschön...wie würdet ihr das schöner machen....etwas c++ style reinbringen...Vars.InterpolateFn(v1 , v2 , frac_a) wir eigentlich in einer anderen funktion aufgerufen...und wird öfters aufgerufen...
cu
-
hab was gefunden: http://www.cpp-tutor.de/cpp/le09/le09_02.htm das sollte über so einen Schnittstellenzeiger funzen: class State { public: void (State::*pfnState)(); void Init(); void State1(); void State2(); void State3(); void Execute(); }; void State::Init() { pfnState = &State::State1; } void State::Execute() { (this->*pfnState)(); }
nur was ist wenn void State1() bis State3() private ist und von typ float?? wie findet ihr das konzept?
cu
-
muster ohne sinn.
aber man meidet funktionszeiger gerne, indem man funktiojnsobjekte benutzt, die von einer gemeinsamen basisklasse erben.