Hi folks. I have a scenario in my code where it looks like I may need to use a linked list *shock horror!*. I would, however, prefer to use an array. I can manage the adding and removal of items from the array myself. But what I want to do is be able to use the array to reference instances of several different object types.
Is it possible to make an array that can store any of several different types?
e.g
Obviously the code to create the array the type instances there is bogus, but it sums up what I need to do. Of course BlitzMax won't accept this as is.
I know that each Type probably has a pointer to it - like an Int Ptr - but Blitz likes to know what type of object the pointer is pointing to - ie a mytype2 Ptr or a mytype4 Ptr. I thought perhaps I could get the pointer to a given type instance and force it into the array as an Int Ptr - and use an array of Int Ptr's?
But then it kind of has to be forced back out again. By forced I mean, type casting and all that or even having to read and write to the array memory directly with PokeInt and PeekInt.
How can I do this? Is there any way? At this time I don't want to resort to a linked list.
I really appreciate your feedback and suggestions.
Thanks
Is it possible to make an array that can store any of several different types?
e.g
Type mytype1 a:int End Type Type mytype2 b#:float End Type Type mytype3 c:String End Type Type mytype4 d:Int[] End Type Local myobjectarray=varioustypes[20] myobjectarray[0]=New mytype3 myobjectarray[1]=New mytype4 myobjectarray[2]=New mytype1 myobjectarray[3]=New mytype2
Obviously the code to create the array the type instances there is bogus, but it sums up what I need to do. Of course BlitzMax won't accept this as is.
I know that each Type probably has a pointer to it - like an Int Ptr - but Blitz likes to know what type of object the pointer is pointing to - ie a mytype2 Ptr or a mytype4 Ptr. I thought perhaps I could get the pointer to a given type instance and force it into the array as an Int Ptr - and use an array of Int Ptr's?
But then it kind of has to be forced back out again. By forced I mean, type casting and all that or even having to read and write to the array memory directly with PokeInt and PeekInt.
How can I do this? Is there any way? At this time I don't want to resort to a linked list.
I really appreciate your feedback and suggestions.
Thanks