I'm trying to pass a pointer to a member function to a non member function as in the following example:
class Main
{
static void runMain (void (*progress)(double))
{
for (int i=1; i<=100; ++i)
{
// Do something
progress(i/100.0);
}
}
};
class A
{
void setProgress (double) {/*Do something else*/}
void runA ()
{
Main::runMain (&setProgress); // Error: incompatible parameter from void(A::*)(double) to void(*)(double)
}
};
class B
{
void updateProgress (double) {/*More things to do*/}
void runB ()
{
Main::runMain (&updateProgress); // The same error
}
};
This result with an error since the type function void( A::* )(double) passed from A to Main is not matching void( * )(double).
How can I pass the member function under the following constraint: I'm not allowed to change the structure of class A and B, except for the runA and runB implementation (but I can change class Main including its function signature).
Thanks!