SFML community forums
Help => System => Topic started by: n00bish on December 04, 2010, 06:33:29 am
-
I built SFML 2.0 this evening and was reading documentation - I'm having issues with sf::Thread giving me errors when using example code found in http://www.sfml-dev.org/tutorials/1.6/system-threads.php
I'm doing the example with a class inheriting from sf::Thread (pretty much the exact code you see there) - and I get a "'MyThread' : no appropriate default constructor available" error. Is there a way to resolve it?
Source is below:
#include <SFML/System.hpp>
#include <iostream>
sf::Mutex GlobalMutex; // This mutex will be used to synchronize our threads
class MyThread : public sf::Thread {
private :
virtual void Run() {
// Lock the mutex, to make sure no thread will interrupt us while we are displaying text
GlobalMutex.Lock();
// Print something...
for (int i = 0; i < 10; ++i)
std::cout << "I'm the thread number 2" << std::endl;
// Unlock the mutex
GlobalMutex.Unlock();
}
};
int main() {
// Create an instance of our custom thread class
MyThread Thread;
// Start it !
Thread.Launch();
// Lock the mutex, to make sure no thread will interrupt us while we are displaying text
GlobalMutex.Lock();
// Print something...
for (int i = 0; i < 10; ++i)
std::cout << "I'm the main thread" << std::endl;
// Unlock the mutex
GlobalMutex.Unlock();
return EXIT_SUCCESS;
}
-
I built SFML 2.0 [...] using example code found in http://www.sfml-dev.org/tutorials/1.6/system-threads.php
Well, you can't read the 1.6 documentation/tutorials and use 2.0. A lot of things have changed, you should rather refer to the 2.0 documentation:
http://www.sfml-dev.org/documentation/2.0/
Tutorials haven't been updated yet, but the documentation should be enough.
-
I built SFML 2.0 [...] using example code found in http://www.sfml-dev.org/tutorials/1.6/system-threads.php
Well, you can't read the 1.6 documentation/tutorials and use 2.0. A lot of things have changed, you should rather refer to the 2.0 documentation:
http://www.sfml-dev.org/documentation/2.0/
Tutorials haven't been updated yet, but the documentation should be enough.
Sorry - you're right. I should have mentioned I also took a look at the documentation here: http://www.sfml-dev.org/documentation/2.0/classsf_1_1Thread.htm
The Usage Example for creating a derived class using sf::Thread also uses the same setup, unless I am mistaken. That's where my confusion lies - since the 1.6 and 2.0 doc seems to match up, and the error still happens even when copying the code from the 2.0 docs.
Thanks for your help.
-
Oops, I forgot to update the doc :lol:
So you should rather refer to the header (the doc is built from the comments in the header).
class MyTask
{
public:
void Run()
{
...
}
};
int main()
{
MyTask task;
sf::Thread Thread(&MyTask::Run, &task);
Thread.Launch();
...
return EXIT_SUCCESS;
}
-
I've updated the doc.
-
Thank you very much!