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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:37:11+00:00 2026-06-12T19:37:11+00:00

My main() looks like this: int main(int argc, char** argv) { // Initialize GLUT

  • 0

My main() looks like this:

   int main(int argc, char** argv)
    {
    // Initialize GLUT
    glutInit(&argc, argv);

    ...

    glutDisplayFunc(display);
    ...

    // Set robot's parameters
    Robot robot; // Initialize global object robot
    robot.setSize(50);
    robot.setColor('G');
    robot.setLocation(50,100);

    glutMainLoop();
    return EXIT_SUCCESS;
}

Then I have another function, which I would like to have access to the methods of the robot:

// This function is constantly "looped"
void display() {
    ...
    robot.draw();
    ...
}

What is the legit way to do it in C++?

  • 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-12T19:37:12+00:00Added an answer on June 12, 2026 at 7:37 pm

    For anyone interested, the question changed, so my old answer is lost to the edits.

    If your display function is required to have a specific signature (void()), you can use std::bind, presuming you have access to C++11:

    void display(Robot &robot){...}
    
    //in main
    Robot robot;
    glutDisplayFunc(std::bind(std::ref(display), robot));
    

    If you don’t have C++11, boost::bind works just as well:

    glutDisplayFunc(boost::bind(boost::ref(display), robot));
    

    If you have neither, you’ll have to store robot more globally.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a code that looks like this: int main () { fstream file;
My code looks somehow like this: //INCLUDES FILE *file; void handlesocket(int socket); int main(int
I've built a jQuery selector for a function which looks like this: $('html').not('.table-main tr[selected]').mousedown(
I'm trying to compile Objective-C code on Ubuntu 12 Linux. main.m looks like this:
It looks like this just sends a ping, but whats the point of that
I have a matrix multiply code that looks like this: for(i = 0; i
I want to have a global names variable, which looks like that char* names[NAMES_CAP];
I'm getting this error from compilator: 1>Linking... 1>main.obj : error LNK2005: int g_win_flags (?g_win_flags@@3HA)
First look at this code: class Program { static void Main(string[] args) { var
Take a look at this code: public class Test { public static void main(String...

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.