I'm trying to send a pointer to a class function to another class for execution. Here's an example:
Code:
class B
{
public:
void DoThis(int num, bool (*p2Func)(std::ofstream&));
private:
std::ofstream m_fileOut;
};
void B::DoThis(int num, bool (*p2Func)(std::ofstream&))
{
(*p2Func)(m_fileOut);
}
class A
{
public:
A() {m_pB = new B();}
~A() {delete m_pB;}
bool Serialize(std::ifstream& ar) {return true;}
bool Serialize(std::ofstream& ar) {return true;}
void DoSomethingElse();
private:
B* m_pB;
};
void A::DoSomethingElse()
{
//do some stuff
m_pB->DoThis(0,Serialize);
}
I get the following compiler error:
error C2664: 'DoThis' : cannot convert parameter 2 from 'bool (std::ofstream &)' to 'bool (*)(std::ofstream &)'
None of the functions with this name in scope match the target type
When I try changing the call to DoThis to:
Code:
m_pB->DoThis(0,&Serialize);
I get the following compiler error:
error C2276: '&' : illegal operation on bound member function expression
I'm not exactly sure what I'm doing wrong. Can someone point me in a better direction?