multithreading - How to create a glfw thread in c++? -


i started using glfw try , built game. i'm new c , c++ worked opengl before android. have got opengl stuff working , started try , make thread glfw.

here basic test code. similar whats in documentation.

#include <gl/glfw.h> #include <stdio.h>  glfwthread thread;  void glfwcall testthread() {     printf("hello\n"); }  int main() {     printf("test\n");      glfwinit();      thread = glfwcreatethread(testthread, null);     glfwwaitthread(thread, glfw_wait);      glfwterminate();     return 1;    } 

this compile fine in gcc , work exspected.

$ gcc -o glthread glthread.c -lglfw $ ./glthread test hello 

the problem want take advantage of c++ features classes game. when compile in g++ this...

$ g++ -o glthread glthread.c -lglfw glthread.c: in function ‘int main()’: glthread.c:18: error: invalid conversion ‘void (*)()’ ‘void (*)(void*)’ glthread.c:18: error:   initializing argument 1 of ‘glfwthread glfwcreatethread(void (*)(void*), void*)’ 

when put in class crucial error changes this.

error: argument of type ‘void (renderer::)()’ not match ‘void (*)(void*)’ 

what want know is, possible create threads using glfw in c++ , if how?

my main pc working on arch linux machine. can't give versions of compilers right now. if can them later.

void glfwcall testthread() {     printf("hello\n"); } 

should receive 1 argument of type void* , cannot use class-functions here, since signature of pointer class function ret (class::*)(args), not void (*)(void*). if want use pointers class-members threads - should use more c++ style libraries (boost::thread, or it, or write own wrapper).

your example works in c, since in c empty brackets (i.e. () ) means - number of parameters of types, in c++ () means, function shouln't receive parameters @ all.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -