function pointer question
I have wracked my brain and cant seem to think of any way to make a container of function pointers. I was wondering if any of you have a solution. I know using virtual functions is better in C++, but that isnt a option at the moment. I would have to do an entire rewrite to do that.
EDIT:
Found a solution on another website using std::vector. I am posting a quick example below
Code:
void test()
{
std::cout << "t\n";
}
int _tmain(int argc, _TCHAR* argv[])
{
typedef void (*fptr)(void);
std::vector<fptr> t;
t.resize(10);
std::vector<fptr>::iterator it;
for ( it = t.begin(); it != t.end(); ++it )
{
(*it) = &test; //set function pointer to void test()'s address
}
for ( it = t.begin(); it != t.end(); ++it )
{
(*it)(); //run the function pointed to by t
}
system("pause");
return 0;
}
Thank you anyhow, and i hope this helps someone else someday.