Array of void

I've got to make an array of voids, like following :
void * varray[100];
varray[0] = &myProc();
where myProc is any function in my programm. Later i wanna call it by the array like this :
how could i do this ?
Who is Participating?
nietodConnect With a Mentor Commented:
You just need to cast the pointer to the type approriate for the function call.

details follow.
First of all, I think it is easiest to work with function pointers if you define a type definition for the pointer (bacause the syntax is ugly and this keeps the uglyness in mostly in one place.)   If you have functions that takes an int as a parameter and return an int, then a pointer type to these functions called "FunPtrTyp" would be declared like

typedef int (*FunPtrTyp)(int);
Now you can convert a void pointer to this type using a cast like

(FunPtrTyp) SomePtr;

For example

int Increment(int i)
   return i + 1;

void *VoidPtr = Increment;

int X = (*(FunPtrTyp) VoidPtr)(5);

(Note that the syntax of the conversion can be simplified a little, but I find this to be clearer than the simpler form.)
The new generation of project management tools

With’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

However, considering the fact that you have a whole table of these, makes me wonder if there isn't a better--more C++--solution to your needs.  That strongly suggests that you might be better of using virtual functions and functors in your design.  Function pointers are unnecessary, and basically a bad idea in C++.  You need them only when you must interface with non--C++ code, like maybe the OS.  If you are working only in C++ (or in COM), then you should reconsider using them.  Virtual functions will give you all the capabilities of function pointers and more and will do so much more safely.

Let me know if you have any questions.
DennisWoodAuthor Commented:
Much thanx for the quick answer, hope you rise up with the points, c u Dennis
rise up?  to where?  I'm the top expert (at least in terms of points) in C++.
All Courses

From novice to tech pro — start learning today.