-
March 9th, 2009, 04:24 PM
#1
[RESOLVED] Yet another callback function question
I have written a class method that uses a callback function. When the function is outside the class (not a class member, but an external C++ method), it works just fine. Being a compulsive encapsulator, I tried putting the same function in the class as a class member -- but it won't compile.
Here's the function prototype:
Code:
void callback_DumpStuff(CBinTreeNode* p,void* pParam);
and here's the function call in a class method:
Code:
m_tree.Traverse(CBinTree::Descending,callback_DumpStuff,NULL);
Here's the function definition as a class member:
Code:
//.. in class CSQLParser header file
public:
void callback_DumpStuff(CBinTreeNode* p,void* pParam);
//.. in class CSQLParser implementation file
void CSQLParser::callback_DumpStuff(CBinTreeNode* p,void* pParam)
{
//..
}
Get this error message when trying to compile with the callback function as a class member:
error C3867: 'CSQLParser::callback_DumpStuff': function call missing argument list; use '&CSQLParser::callback_DumpStuff' to create a pointer to member
What the %#@! does that mean, and why does it only work as a non-member function?
Last edited by Mike Pliam; March 9th, 2009 at 04:29 PM.
Reason: clarification
mpliam
-
March 9th, 2009, 04:38 PM
#2
Re: Yet another callback function question
Because class member functions require an object to operate on (this is the implicit "this" parameter). However, if you make the member function static, it will work (since static member functions do not need an object).
Viggy
-
March 9th, 2009, 06:20 PM
#3
Re: Yet another callback function question
Thanks MrViggy. Your fix works.
mpliam
-
March 9th, 2009, 09:15 PM
#4
Re: [RESOLVED] Yet another callback function question
Originally Posted by Mike Pliam
Get this error message when trying to compile with the callback function as a class member:
http://www.parashift.com/c++-faq-lit....html#faq-33.2
Regards,
Paul McKenzie
-
March 12th, 2009, 01:19 PM
#5
Re: [RESOLVED] Yet another callback function question
Interesting. Thanks, Paul.
mpliam
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
|