Jump to content
  • Advertisement
Sign in to follow this  
mattor

Can you make an array of functions?

This topic is 5009 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

And if so, how...or is this related to function templates? If it is, where can I find a good tutorial/reference on what function templates are and how to use them. Thanks

Share this post


Link to post
Share on other sites
Advertisement
do you mean function pointers?

int foo1(int a)
{
return a+1;
}

int foo2(int a)
{
return a*2;
}

int(*funcArray[])(int) = {foo1,foo2};



edit: thanks smart_idiot
that would have given me a headache if i tried that in one of my projects

[Edited by - mike25025 on March 1, 2005 9:46:42 PM]

Share this post


Link to post
Share on other sites
I think the function pointers might not work for what I want, which is to make an array of functions that are each already in their own .cpp file. I wouldn't even know where to declare the function pointer array...maybe I could write a class with the function calls as functions of the class? (he thinks to himself)

Share this post


Link to post
Share on other sites
Quote:
Original post by mattor
I think the function pointers might not work for what I want, which is to make an array of functions that are each already in their own .cpp file. I wouldn't even know where to declare the function pointer array...maybe I could write a class with the function calls as functions of the class? (he thinks to himself)


If I understand you correctly, the easiest way to do this is likely to use some more string friendly language [like perl] to parse the local cpp file for the functions you'd like to make into an array, and then generate c code [essentially a header that only contains the function pointer table] before you do any compilation.

Though umm, you might want to specify why exactly. Folks here might be able to point you to a better solution or help you think through the problem more thoroughly.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!