Have got a problem wit pointer-to-funtion in C++, so here it goes...
I want to define some functions in some class A that I can give as arguments to a function from some other class B. However I cannot make this work. First I have made this small program that actually works...
Code:
#include <iostream>
using std::cout;
using std::endl;
bool testMethod()
{
return false;
}
bool test(bool (*method)())
{
return (*method)();
}
int main()
{
cout << test(testMethod) << endl;
return 0;
}
And then I moved on to doing something like this, which does
not work...
Code:
class Test
{
public:
bool someMethod(void)
{
return false;
};
bool testMethod(bool (*method)(void))
{
return (*method)();
};
void test()
{
bool t = this->testMethod(someMethod);
};
};
The error message I get when I do this is like the following...
Code:
error C2664: 'Test::testMethod' : cannot convert parameter 1 from 'bool (void)' to 'bool (__cdecl *)(void)'
Is it some kind of typecasting problem? And how to get around it? It is the same error message I get if I set up the two class that I want.
Thanks in advance...
Jacob.