class A
{
public:
long AFunc(void(*pfn)(void))
{
//Do something
}
};
long MyFunc();
void main()
{
A MyA;
MyA.AFunc(&MyFunc); //This is ok
}
long MyFunc()
{
//Do something
}
As could see, the above is legitimate. However,
//Assume class A is defined
class B
{
protected:
A m_MyA;
public:
void BFunc()
{
m_MyA.AFunc(BFunc2); //Illegal
}
long BFunc2()
{
//Do something
}
};
Function pointers and classes
Analyze:
I could declare AFunc to take a pointer to a member function of B, but I don't want A to be dependant on B, in case I want to use A in another class.
Does anyone know how to go around this? I don't think static member function would work neither. Thanks.
[edited by - vbisme on May 27, 2003 4:14:30 PM]
In class B I assume that you meant m_MyA.AFunc(&BFunc2) and not just m_MyA(&BFunc2) right? well anyway...
BFunc is of type
long(B::*pfn)(void)
and it is NOT of type
long(*pfn)(void)
you see BFunc is inside the scope of class B. Thats why it''s B::*pfn instead of just pfn
:::: [ Triple Buffer V2.0 ] ::::
BFunc is of type
long(B::*pfn)(void)
and it is NOT of type
long(*pfn)(void)
you see BFunc is inside the scope of class B. Thats why it''s B::*pfn instead of just pfn
:::: [ Triple Buffer V2.0 ] ::::
quote:Original post by vbisme
So there is noway I could define AFunc to take a class function pointer unless I specify so?
that is correct. They are different data types. You can however use something like a callback class instead. Im not too sure how it works but...hold on...
*goes to articles section on gd*
...peh, nothing there.
*trots off to flipcode*
!!. I think this is what you might need/want/require:
Clicky
:::: [ Triple Buffer V2.0 ] ::::
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement