Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
Alter Hase
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 |
template<typename... params> class Callback{ //... template<void (*Function)(params...)> Callback(){ // Pointer speichern } } |
C-/C++-Quelltext |
|
1 2 3 |
void foo(int i){...}; Callback<int> cb<foo>; |
Community-Fossil
Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer
Alter Hase
Community-Fossil
Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer
Community-Fossil
Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer
Alter Hase
Community-Fossil
Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 |
template<typename... params> class Callback{ //... public: Callback(void (*f)(params...)){ // Pointer speichern } }; Callback<int> cb(foo); |
Alter Hase
C-/C++-Quelltext |
|
1 2 3 4 5 |
template<void (*Function)(params...)> Callback() : instance{nullptr} , func{&functionStub<Function>} {} |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
template<typename... params> class Callback{ private: using InstancePtr = void*; using FuncPtr = void(*)(InstancePtr, params...); FuncPtr func; // Function to be called. InstancePtr instance; // Instance to operate on. template<void (*Function)(params...)> static inline void functionStub(InstancePtr, params... param){ (Function)(param...); } template<class T, void(T::*Function)(params...)> static inline void methodStub(InstancePtr instance, params... param){ (static_cast<T*>(instance)->*Function)(param...); } public: Callback() : func(nullptr) , instance(nullptr) {} // Mein 'Versuch' es in einen Konstruktor zu packen. template<void (*Function)(params...)> Callback() : instance{nullptr} , func{&functionStub<Function>} {} template<void (*Function)(params...)> void bind(){ func = &functionStub<Function>; } template<class T, void(T::*Function)(params...)> void bind(T* instance){ this->instance = instance; func = &methodStub<T, Function>; } void operator()(params... param){ func(instance, std::forward<params>(param)...); } }; |
Dieser Beitrag wurde bereits 4 mal editiert, zuletzt von »Julién« (16.06.2016, 20:13)
Werbeanzeige