|
-
April 16th, 1999, 11:50 AM
#3
Re: Function Pointer
I think the problem is that you are assigning a member function pointer to a global function pointer. In C++, you can't do this.
The function type of CMyProject::GetDate() is not void (*Func)() but void (CMyProject::*Func)(). You need to do the following (I use typedefs since
function pointers tire me out):
typedef void (CMyProject::*FUNCPTR)();
typedef struct {
...
FUNCPTR Func;
} ITEM, *pItem
void CMyProject::Add( char *szItemName, FUNCPTR Func)
{
// Add a new data type
pITEM pData = new ITEM();
strcpy(pData->szTypeName,szItemName);
pData->Func = Func;
m_aDataType.Add(pData);
}
The call is invoked by doing this:
(pData->*Func)();
This is tough syntax to remember, but the bottom line is that in C++ non-static member functions have a hidden extra parameter ("this"), so you cannot declare it the same way as a global / static function pointer.
Regards,
Paul McKenzie
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|