Skip to main content
gamedev.net
🔒 Locked

Dynamic array of function pointers.. help....

Started by n0ob Mar 20, 2003 at 4:09 PM 4 replies 150+ views
Original Post
n0ob
n0ob
Let''s say I have a function and I want to use it to initialize an array of function pointers of type void and take a BULLET pointer: void (*function_list)(BULLET*pBul); SetFunctions(void (*funclist)(BULLET*pBul),int num) I was thinking something like: funclist = new (insert something here)[num]; I can''t quite seem to find information on dynamic arrays of function pointers, while i can find stuff on pointers, or function pointers... I''d really appreciate any help!! Thanks for your time! Kings of Chaos
Spudder
Spudder
I''ve never used function pointers so i cant help in that regard but i can point (pardon the pun) in the direction of this site which should help you:
http://www.function-pointer.org/
kuphryn
kuphryn
Use typedef to make code easier to understand. One solution is a container of function pointers.

Kuphryn
Dwiel
Dwiel
I havn''t used function pointers for awhile, but using a typedef makes thing much easier:


  

typdef float (*functptr)(float, float)

functptr *pointers;
pointers = new functptr[numof];
delete [] pointers;



Try that...

Hope this helps

Dwiel
Xai
Xai
also of interest ... if you can use C++ functors, then you can use an array of pointers to a base functor class, and it will work just like any other kind of polymorism ... of course i think you pay 1 extra pointer indirection if you use a virtual functor ... hmm

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.