About Store Forum Documentation Contact



Post Reply 
Button function within a class
Author Message
kulesz Offline
Member

Post: #1
Button function within a class
How can I add a class member as a button callback in a class?
For example:

Code:
struct MyChatbox
{
    Window       window; // gui  window
    Region       region; // gui  region
    Button       add   ; // add  message button
    ChatMessages chat  ; // chat messages

    Region chatRegion;
    TextLine textLine;
    list <string> lines;

    void set(string &text);
    void draw();

    void AddMessage(Ptr)
    {
        chat.New("New Custom Message");
        region.scrollToY(9999);
    }

    void create()
    {
        textLine.create(Rect(0, 0.5, 0.5, 0.55), "Command");
    
        Gui   +=window.create(Rect(-0.5f , -0.4f, 0.5f ,  0.4f),"Chatbox");
        window+=region.create(Rect( 0.05f, -0.6f, 0.95f, -0.1f));
        window+=add   .create(Rect_C(window.crect.w()/2, -0.67f, 0.3f, 0.06f),"Add Message").func(AddMessage);
        region+=chat  .create();

        region.scrollToY(9999);
    }
};

gives me an error:
Code:
error C3867: 'MyChatbox::AddMessage': function call missing argument list; use '&MyChatbox::AddMessage' to create a pointer to member

Changing AddMessage to &MyChatbox::AddMessage doesn't work.
07-12-2011 07:54 PM
Find all posts by this user Quote this message in a reply
Esenthel Online
Administrator

Post: #2
RE: Button function within a class
void AddMessage(Ptr) -> static void AddMessage(Ptr)
07-12-2011 07:56 PM
Find all posts by this user Quote this message in a reply
kulesz Offline
Member

Post: #3
RE: Button function within a class
Well, it's OK, but I can't use non-static members inside the function then.
07-12-2011 08:11 PM
Find all posts by this user Quote this message in a reply
Post Reply