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 9230323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:47:51+00:00 2026-06-18T05:47:51+00:00

I am trying to create a window container for sfml windows. If you are

  • 0

I am trying to create a window container for sfml windows. If you are not familiar with sfml, a sfml window is a class which is non-copyable so cannot be put inside a std::vector for example.

I’ve done most of the work, but I am now trying to implement some sort of callback function which will do the open-gl drawing work before window.Display() is called to update the window.

I cannot get my head around the syntax of a callback function (either c or c++ version). Would someone be willing to explain an example to me?

Even better, would someone be willing to explain an example of how to implement a callback function in a class, so that a function (which the user defines) can be passed into a function of the class which will remember what that function was so it can be called by the class later.

To make that above sentence clearer: I think there are three things I need:

1): A function which the user defines, for example:

void doDrawing(){
    // do some open gl stuff
}

2:) A function inside a class which takes the argument of the above, user defined function:

void setDisplayFunc( ?argument of a function? argument ){
    function_pointer pointer = argument;
}

I have no idea what the type of ‘argument’ should be, or what ‘function_pointer’ has to be… I think this is where I am most stuck!

3:) A way in which the class can call the function which was assigned above.

// Do the function which is pointed at by pointer, which is of the type 'function_pointer' ... Whatever function_pointer happens to be!

If anyone has used glut before, then I guess I am trying to implement the glut callback functions which look like:

void someDisplayFunction(){
    // do open gl stuff
}

glutDisplayFunc( someDisplayFunction );

The above function takes the argument of a user-defined function and then does it when we call ‘glutPostRedisplay’ …

I hope this makes sense, I have tried to include as much information as I can to help. Any help is appreciated. (:

  • 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-06-18T05:47:52+00:00Added an answer on June 18, 2026 at 5:47 am

    You want a function pointer. In your case:

    typedef void (*function_pointer)();
    

    With that you can write:

    void setDisplayFunc(function_pointer argument){
        function_pointer pointer = argument;
    }
    

    To call it you simply do:

    pointer();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a status window which content(textbox) should change in a
I'm trying to programmatically create a window with my own custom OpenGL NSView as
I'm trying to create a preferences window. In it I have some checkbox style
I am trying to create a child window in WPF.this child window should open
I am trying to create a sort of a window, formed by multiple divs.
I am trying to create a very simple chat window that simply has the
I am trying to create an application that makes a window (external to the
I am trying to create a series of dynamic, calculated fields on my window.
I'm trying to create a windows phone app with lots of texts like this
I am trying to create a windows explorer. I have succeeded in populating the

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.