function pointers

BlitzMax Forums/BlitzMax Beginners Area/function pointers

SSS(Posted 2007) [#1]
hey everyone, I'm having a little bit of trouble with function pointers. I understand how they work in general but I can't seem to get them working using methods instead of functions. Is this expected behavior and is there any way to get around this? Thanks!

As an example, I want to do something like this,
Type test
	Method increment(a)
		Return a + 1
	End Method
End Type


t:test = New test
Local l(a) = t.increment

Print l(1)


but it doesn't appear to work.


CS_TBL(Posted 2007) [#2]
That's a method. Function pointers point to functions.. (yes, join the club o' ppl wanting method pointers)


Dreamora(Posted 2007) [#3]
there is nothing like a method pointer.
thats called a delegate or agent, as you can not point to a method on something that is itself already a reference as its position in RAM isn't static (the GC is allowed and meant to defragment the RAM pool it is using), ie an object itself that points to the object and knows how to call the method. (how BM most likely will be able to do as well when Mark is done with what he is up to right now)


ImaginaryHuman(Posted 2007) [#4]
The only way around this at the moment is to change from using methods to using functions and at some point passing the object as a parameter to the function so it can refer to the fields. In my tests, doing myobj.field=xyz is no faster OR slower than field=xyz from within a method. It's just that you have to pass the object to the function, which is partly what the method does anyway.