How to create New array of function pointers?
BlitzMax Forums/BlitzMax Programming/How to create New array of function pointers?
| ||
In the below code structure, how do I create a new array of function pointers from within the mymethod() method?Type MyType Field MyFunctions()[] 'Future array of function pointers Method New() MyFunctions=Null End Method Method MyMethod() MyFunctions=New ()[100] 'How? End Method End Type I already know you can just define the size as part of the Field, and also that you can probably do it in New(), but I need to do it in a different method. How can I create the function pointer array after having already said that it can potential exist as a field? Thanks. |
| ||
This depends on the return type of your functions ... a new int() [100] should work without superstrict ... don't know how to do with superstrict if you don't have a return type ... |
| ||
Try this until someone suggests a better way: Method MyMethod() Local f()[100] MyFunctions=f f=Null End Method |
| ||
If I understand what you want (and I very well may not), you want to clear the array and the resize it? If so, can you not just do: Type MyType Field MyFunctions()[] 'Future array of function pointers Method New() MyFunctions=Null End Method Method MyMethod() MyFunctions=MyFunctions[..0] 'resize to 0 elements MyFunctions=MyFunctions[..100] 'resize to 100 elements End Method End Type |
| ||
Ok. I'm not trying to clear the array. I just have a trend throughout my code to define all the Fields without saying what they contain, so MyFunctions()[] to start out with. Then for the New() method, I am also not defining what they contain, I am just initializing the data to Null and 0 or whatever represents a non-initialized state. Then in my own method I want to set up whatever size the array should be based on a value passed from somewhere else. ie. Method MyMethod(MSize:Int) 'set up the array to that size End Method As to the other suggestion, how could I define it as a New Int() [Size] and it still be considered an array of function pointers? Blitz wont accept that as valid syntax. However, based on your concept, Perturbatio, the following actually works: Method MyMethod(MSize:Int) MyFunctions=MyFunctions[0..MSize] 'Resize it as a slice End Method Thanks! |