Thread: callback in a class, what do I do?

  1. #1
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    2,158

    callback in a class, what do I do?

    I have a window callback in a class, and I want to access another varible in that class from the callback, but when I put the name of the varible down in there, it doesn't recognize it. So how do you access another member of a class from a callback member?

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    62
    Your callback function is static, isn't it? In that case you can only access static members.

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    Pass a pointer to the object to the static callback, then cast that to the object and call a member function from it.

  4. #4
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    2,158
    But it's a callback, I only need to access other members when all the arguments are taken.

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    So, if I get it right, you are saying that the callback has no "spare" or "user defined" parameters that you could use to pass for example a pointer to your object?

    Can you perhaps tie the object to some parameter that is known (and unique) in the callback - for example, if you have a "HWND" that is a handle to your particular window, you could use that in to find your object back again, by having a structure like this:

    Code:
    struct hwnd_to_object
    {
        HWND hwnd;
        CObject *pObject;
    } hwnd_list[10];
    
    ...
       i = find_next_free(hwnd_list);
       hwnd_list[i].hwnd = hwnd;
       hwnd_list[i].pObject = myObject;
    ...
    I'm not saying you have to use the HWND, but anything that is unique that is known at bot ends of the call is what you need.

    --
    Mats

  6. #6
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    2,158
    Hmm, good idea. Thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. deriving classes
    By l2u in forum C++ Programming
    Replies: 12
    Last Post: 01-15-2007, 05:01 PM
  3. Replies: 8
    Last Post: 10-02-2005, 12:27 AM
  4. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 07:18 AM