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
Zitat von »"drakon"«
Du kannst eine Memberfunktion nicht gleich übergeben, wie eine freie Funktion. (ala Rückruffunktion und co.)
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 |
#include <iostream> using namespace std; class test { public: void Hallo() { cout << "Hallo"; } }; typedef void (test::*func)(); void call(void* p) { test d; func f = (func)p; (d.*f)(); } int main() { call(reinterpret_cast<void*>(&test::Hallo)); cin.get(); return 0; } |
Quellcode |
|
1 2 3 4 |
e:\c++\workspace\test\test\main2.cpp(21) : error C2440: 'type cast' : cannot convert from 'void *' to 'func' There is no context in which this conversion is possible e:\c++\workspace\test\test\main2.cpp(31) : error C2440: 'reinterpret_cast' : cannot convert from 'void (__thiscall test::* )(void)' to 'void *' There is no context in which this conversion is possible |
C-/C++-Quelltext |
|
1 2 3 4 5 |
union { void *ptr; memptr mem; }; |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
void call(func p) { test d; func f = p; (d.*f)(); } int main() { call(&test::Hallo); cin.get(); return 0; } |
Werbeanzeige