Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6192583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:58:03+00:00 2026-05-24T02:58:03+00:00

Hey i’m trying to make a very simple GUI using SFML, and i want

  • 0

Hey i’m trying to make a very simple GUI using SFML, and i want to be able to attach a function to my Button class in the constructor, as so the user can define what happens when the button is pressed.

I’ve worked a little before with GLUT and noticed these declerations:

glutReshapeFunc(Resize);
glutDisplayFunc(Draw);

Which apparently define what function should be called when the window is resized or displayed. I want something exactly like this for my button so upon construction you can define what function should be called. I want to be able to pass a function name just like glut, not having define a new class wich overides a virtual functin.

  • I also doubt it’s possible however to pass parameters for these
    called functions, as you never know what or how many there would be.
    Am i right?

So anyway….. How do i accomplish this or something like it?? Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T02:58:04+00:00Added an answer on May 24, 2026 at 2:58 am

    You can store a callback using e.g. std::function (for C++0x; boost::function is also available and has a similar interface).

    #include <functional>
    
    class Button {
    public:
        template<typename T>
        explicit
        Button(T const& t): callback(t) {}
    
        void
        press()
        {
            callback();
        }
    
    private:
        std::function<void()> callback;
    };
    
    // example use with a lambda
    Button b([] { do_stuff(); });
    b.press(); // will call do_stuff
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey, I got a very simple problem. I want to change a float inside
Hey there, I'm at the moment trying to make a product management application. The
Hey guys. I'm trying to configure TFS2010 on a home server. I want to
Hey, I'm trying to make an Address book for my site and I was
hey guys, I have mypage.com/user-login.php?action=register and I want to be able to call mypage.com/register
hey, I want to be able to have a gradient fill on the text
Hey there, i am trying to make a little app that will serve multiple
Hey everyone, I'm using Virtual PC and working with a virtual hard disk (*.vhd)
Hey so what I want to do is snag the content for the first
Hey, I'm using Levenshteins algorithm to get distance between source and target string. also

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.