• C

Pointer to Functions ?

 I have question regarding pointer to functions ? I have written the piece of code just below and my query follows after that.

------------Start of Code --------------
// a function definition
void x(void (*pointfunction)(void))
  void *ptr = pointfunction;

// Call made to x
void foo()
// My pointer to the function
void (*pointfunc[3])(void) =

  for (int i =0; i<3;i++)
void func1()
   printf("Hello, world -- 1");
void func2()
   printf("Hello, world -- 2");
void func3()
   printf("Hello, world -- 3");
------------------End of code---------
In the above piece code, in the function "x()" how can "func1" or "func2" or "func3" be called using the the "void *ptr". Detailed explanation would be appreciated.
Note: I am using VC++. I dont have any compiler problems.

Thanx in anticipation.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I don't know how you got no compiler problems, because this code sure doesn't compile on my system. To call a function pointed to by a pointer try this ptr->Function();

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.