A
Azdo
Hi,
is it possible to pass a member function pointer to other member
function of the same class in order to get different behaviours?
Something like
class A
{
int m(int d) /* First way */
{
return d;
}
int n(int d) /*Second way*/
{
return d+2;
}
/* This does the calculations depending on the function passed */
void f(int (*g)(int))
{
std::cout << g(8) << "\n";
}
void start()
{
f(&m); /* Do it the "m" way */
f(&n); /* Do it the "n" way */
}
};
What I am trying to accomplish is to have a member function that can
call different procedures to do slightly different jobs.
Thank you,
is it possible to pass a member function pointer to other member
function of the same class in order to get different behaviours?
Something like
class A
{
int m(int d) /* First way */
{
return d;
}
int n(int d) /*Second way*/
{
return d+2;
}
/* This does the calculations depending on the function passed */
void f(int (*g)(int))
{
std::cout << g(8) << "\n";
}
void start()
{
f(&m); /* Do it the "m" way */
f(&n); /* Do it the "n" way */
}
};
What I am trying to accomplish is to have a member function that can
call different procedures to do slightly different jobs.
Thank you,