Archived

This topic is now archived and is closed to further replies.

thorpe

Function pointer array

Recommended Posts

I have a class in which I have alot of functions which I would like to place in an array and then call them from that array. How do I do it? (I''m completely new to function pointers and I can''t get them to work within a class) Johan Torp - http://www.destruction.nu

Share this post


Link to post
Share on other sites
I came up with this but it won''t work


  
//class.h:


void (class::*(Functions[2][10]))();

//class.cpp:


Functions[x][y]();



When I try this, the compiler complaints:
class.cpp(x) : error C2064: term does not evaluate to a function

It typechecks if I just type:
Functions[x][y];

But it doesn''t call any function!

Help!

Johan Torp - http://www.destruction.nu

Share this post


Link to post
Share on other sites
You don''t dereference your pointer

Try

(this->(*(Functions[x][y])))();

You can probably remove some parentheses (and probably the this, too), but I''d rather be on the safe side.

Cédric

Share this post


Link to post
Share on other sites