gshivag
asked on
Pointer to Functions ?
Hello,
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) =
{
func1,func2,func3
};
for (int i =0; i<3;i++)
x(pointfunc[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.
gshivag
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) =
{
func1,func2,func3
};
for (int i =0; i<3;i++)
x(pointfunc[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.
gshivag
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.