"method"-pointer
BlitzMax Forums/BlitzMax Programming/"method"-pointer
| ||
is there a way to have a function-pointer pointing to a method inside a user defind type? thx |
| ||
no |
| ||
Dang, simplest answer of the year and I didn't get there first. ;-) A function within a type, you can get the function pointer for ... However, it is not instance specific. It's the same function used by all instances of that type, stored at the same address. You would have to pass parameters to make it instance specific. I'm not really sure why you couldn't have Method Pointers or just function pointers to methods. |
| ||
I assume that the overhead for the GC when it had to handle exact pointers for the object in memory (which would be needed for method pointers) would have been too large ... But theoretically you could fake it using TMap to save the object (and find it again in acceptable speed) and using a function to which you give the object and a the needed data to get the method and execute it. |
| ||
I'd do it as a function with the first parameter a "_Self" parameter and just pass the object into that and refer to everything as "_Self.(...)" |
| ||
ok, so thanks. it's not gona be that hard to work aroud it. i just wanted to use "methodpointers" to avoid typecasting. i have two different types extending a third type and all the instances of the first two types handled in one list because they bahave very similar, but have (e.i.) a different draw() method, so i thought i could store a pointer to the method of the type they belong to instead of having to check wether the object is of type one and then call the apropriate method... |