threas

template<typename F >
sf::Thread::Thread ( F function )

Construct the thread from a functor with no argument.

This constructor works for function objects, as well as free function.

Use this constructor for this kind of function:
void function();
// --- or ----
struct Functor
{
void operator()();
};

Note: this does not run the thread, use Launch().
what does the last line mean?
Did you read the SFML documentation on Thread?
http://www.sfml-dev.org/tutorials/2.0/system-thread.php

Once you've created a sf::Thread instance, you must start it with the launch function.
1
2
sf::Thread thread(&func);
thread.launch();

launch calls the function that you passed to the constructor in a new thread, and returns immediately so that the calling thread can continue to run.
The sf::Thread::Thread function Creates a thread, in other words it loads it into memory. You need to call sf::Thread::launch() in order for it to execute. In Windows it is the equivalent of calling the "CreateThread()" function with the 'CREATE_SUSPENDED' creation flag. With very few exceptions threads should be created in a 'suspended' mode so that synchronization objects\functions can receive valid handles to them.
when i do this i got this i get the following error.

sf::Thread thread( &sf::TcpSocket::receive, socket);
thread.launch();

error on the first argument is the unknown type error.

and when i do this

void send( sf::TcpSocket socket )

and create a thread like this

sf::Thread thread( &send, socket);
thread.launch();
get the following error

Error 1 error C2248: 'sf::NonCopyable::NonCopyable' : cannot access private member declared in class 'sf::NonCopyable' c:\users\destraction\desktop\laurentgomila-sfml-ef78b6d\include\sfml\network\socket.hpp 178 1 sfml 3.0

I don't know about the first error but the second error is because you can't copy an sf::TcpSocket like you are trying to.
The first error is because you don't pass functions by reference like that, just use the name of the function.
The first error is because you don't pass functions by reference like that, just use the name of the function.


He wasn't passing by reference, he was taking the address, which isn't necessary for freestanding functions, but is required to get a member function address. The error is indicated because sf::TcpSocket::receive does not have the correct signature for use as an argument to sf::Thread. (The member function should take no arguments other than the implicit this pointer which should be the second argument to the sf::Thread constructor.)
Last edited on
Topic archived. No new replies allowed.