简体   繁体   中英

Passing main arguments to a second thread for freeglut launch

I am new to OpenGL and Freeglut and am wanting to create a thread for the peripheral graphics output that is not the Operating system thread. When I create the second thread I want to pass the main command line arguments so I can initialise freeglut.

I am using:

Name: Code::Blocks, Version: 20.03-r11997, SDK Version: 2.0.0, Scintilla Version: 3.7.5, Compiler Name: GNU GCC Compiler.

OS Name: Ubuntu 20.04.3 LTS, OS Type: 64-bit, GNOME Version: 3.36.8, Windowing System: X11.

error: static assertion failed: std::thread: arguments must be invocable after conversion to rvalues

#include "Thread.h"
#include <thread>

#include <GL/glut.h>

class Thread
{
    public:
        Thread()
        {

        }
        ~Thread()
        {

        }
        static void run_Td_1(int argc, char *argv[])
        {
            glutInit(&argc, argv);
            glutInitWindowSize(640,480);
            glutInitWindowPosition(10,10);
            glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);

            glutCreateWindow("GLUT Shapes");

            glutMainLoop();
        }

    protected:

    private:
};

int main(int argc, char *argv[])
{
    std::thread td_1(Thread::run_Td_1, &argc, argv);

    return EXIT_SUCCESS;
}

How to I pass the arguments correctly?

Remove the ampersand character ( & ) from the argc argument:

std::thread td_1(Thread::run_Td_1, argc, argv);

Thread::run_Td_1() expects an integer for its first argument, not a pointer to an integer.

You can try to reproduce the error and experiment here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM