"method"-pointer

BlitzMax Forums/BlitzMax Programming/"method"-pointer

SB(Posted 2006) [#1]
is there a way to have a function-pointer pointing to a method inside a user defind type?

thx


Dreamora(Posted 2006) [#2]
no


ImaginaryHuman(Posted 2006) [#3]
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.


Dreamora(Posted 2006) [#4]
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.


taxlerendiosk(Posted 2006) [#5]
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.(...)"


SB(Posted 2006) [#6]
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...