Hi again everybody.
I know there are some references to this kind of thing around the web but none of them are simple enough for me to understand.
In my code below, I am trying to initialize a function pointer with a class member function but I'm not sure I understand how.
For simplicity my function pointer "myfunction" is to be initialized with myclass::class_function.
How do I do this?
Thank you.
#include <iostream>
#include <cstdlib>
using namespace std;
class myclass
{
public:
void class_function()
{
cout << "Class Function Called" << endl;
}
};
int main()
{
void(*myfunction)();
myclass cls;
myfunction = cls.class_function; // I get an error here.
//C:\CodeBlocksFiles\All\FunctionPointers\main.cpp:31:15: error: cannot convert
//'myclass::class_function' from type 'void (myclass::)()' to type 'void (*)()'
system("pause>nul");
}