Function Pointers for Methods?

BlitzMax Forums/BlitzMax Programming/Function Pointers for Methods?

There are no method pointers at this time. You can get the function pointer to a function within a type, though, but it will be the exact same pointer for all instances of the type, and won't be instance-specific (you'd have to pass the object handle as a paramter).

I wonder if it's because, you can have a pointer to a function within a type because it's tied to the type and not the instance, so if there are no instances of the type then the function won't work anyway, logically. So this way they can create the function at compile time and get a pointer for it. It doesn't change at runtime. With methods, you would be creating new functions at new addresses with each instance at runtime, and that would break because you could create a method, get its pointer, erase the instance and then still have a method pointer pointing to a non-existent method. If you then called it it would crash. You don't get that problem with the function within the type because it's one function shared among all instances and so can be predetermined - your code would have to be logically correct to compile so there are no loopholes.

To have method pointers you'd have to have a way of getting rid of the method pointer when you erase the type instance, which means keeping track of which pointers are associated with which instance, which is quite a task.