Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Syntax Error in initializing a Thread  (Read 3126 times)

0 Members and 1 Guest are viewing this topic.

rojan_neo

  • Newbie
  • *
  • Posts: 28
    • View Profile
    • http://makeagame.tumblr.com
Syntax Error in initializing a Thread
« on: September 19, 2011, 03:05:24 am »
I am using SFML 1.6 and trying to implement a simple thread as in the following code
Code: [Select]

#include <SFML\Graphics.hpp>
#include <iostream>


using namespace std;
using namespace sf;
void THreadFunc()
{
  ...
}

int main()
{
RenderWindow window(VideoMode(800,600,32), "Box2D");
Event events;
Thread thread(&THreadFunc);
while(window.IsOpened())
{
while(window.GetEvent(events))
{

}

...

window.Clear();
window.Draw(sp);

window.Display();
}


return EXIT_SUCCESS;
}

Now during initialization
Code: [Select]


Thread thread(&THreadFunc);

I get the following error
Code: [Select]


Error 3 error C2664: 'sf::Thread::Thread(sf::Thread::FuncType,void *)' : cannot convert parameter 1 from 'void (__cdecl *)(void)' to 'sf::Thread::FuncType'



Can anyone help??

Disch

  • Full Member
  • ***
  • Posts: 220
    • View Profile
Syntax Error in initializing a Thread
« Reply #1 on: September 19, 2011, 04:34:30 am »
In SFML 1.6, the thread function must take a void* parameter:

Code: [Select]

void THreadFunc(void* userdata)
{
  //...
}

rojan_neo

  • Newbie
  • *
  • Posts: 28
    • View Profile
    • http://makeagame.tumblr.com
Syntax Error in initializing a Thread
« Reply #2 on: September 19, 2011, 02:58:18 pm »
what if I have more than one parameters of different types

omeg

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
    • http://omeg.pl/
Syntax Error in initializing a Thread
« Reply #3 on: September 19, 2011, 03:17:27 pm »
Quote from: "rojan_neo"
what if I have more than one parameters of different types

Pass a pointer to a struct that contains all the data you need.