P
Praetorian
Hi,
I'm having huge syntax problem dealing with function pointers. Here's
what I'm doing:
I have 2 classes, ClassA and ClassB. ClassA owns an instance of
ClassB. What I want to do is pass a function pointer to a member
function of ClassB as a parameter to a member function of ClassA. I
don't want ClassA's member function to call ClassB's function directly
because ClassA can be used in 2 ways, one of which is a case in which
it does not create an instance of ClassB; hence by passing a function
pointer I can handle that case easily.
This is the code I have:
class ClassB {
public:
BOOL GetFlagX(void) { return m_bFlagX;};
private:
BOOL m_bFlagX;
};
class ClassA {
public:
typedef BOOL (ClassA::*FPAbortFlag)(void);
FPAbortFlag m_fpAbort;
protected:
ClassB *m_pClassB;
BOOL ClassAMemFcn(FPAbortFlag fpAbort);
};
In this case ClassA has new'd an instance of ClassB. What I want to do
is have ClassA's function pointer 'm_fpAbort' point to ClassB's
'GetFlagX' function. Can't seem to figure out the syntax for this.
I did get the following to compile but it wasn't pointing to the
member function associated with ClassA's instance of ClassB:
m_fpAbort = (FPAbortFlag)(&(ClassB::GetFlagX));
How do I do this?
Thanks in advance,
Ashish.
I'm having huge syntax problem dealing with function pointers. Here's
what I'm doing:
I have 2 classes, ClassA and ClassB. ClassA owns an instance of
ClassB. What I want to do is pass a function pointer to a member
function of ClassB as a parameter to a member function of ClassA. I
don't want ClassA's member function to call ClassB's function directly
because ClassA can be used in 2 ways, one of which is a case in which
it does not create an instance of ClassB; hence by passing a function
pointer I can handle that case easily.
This is the code I have:
class ClassB {
public:
BOOL GetFlagX(void) { return m_bFlagX;};
private:
BOOL m_bFlagX;
};
class ClassA {
public:
typedef BOOL (ClassA::*FPAbortFlag)(void);
FPAbortFlag m_fpAbort;
protected:
ClassB *m_pClassB;
BOOL ClassAMemFcn(FPAbortFlag fpAbort);
};
In this case ClassA has new'd an instance of ClassB. What I want to do
is have ClassA's function pointer 'm_fpAbort' point to ClassB's
'GetFlagX' function. Can't seem to figure out the syntax for this.
I did get the following to compile but it wasn't pointing to the
member function associated with ClassA's instance of ClassB:
m_fpAbort = (FPAbortFlag)(&(ClassB::GetFlagX));
How do I do this?
Thanks in advance,
Ashish.