CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    May 2002
    Posts
    1,798

    [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

  2. #2
    Join Date
    Feb 2002
    Posts
    4,640

    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

  3. #3
    Join Date
    May 2002
    Posts
    1,798

    Re: Yet another callback function question

    Thanks MrViggy. Your fix works.
    mpliam

  4. #4
    Join Date
    Apr 1999
    Posts
    27,449

    Re: [RESOLVED] Yet another callback function question

    Quote Originally Posted by Mike Pliam View Post
    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

  5. #5
    Join Date
    May 2002
    Posts
    1,798

    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
  •  





Click Here to Expand Forum to Full Width

Featured