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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - Slasher133

Pages: [1]
1
System / 1.6 Threads when using classes
« on: April 06, 2012, 07:07:06 am »
I'm not sure what I am doing wrong, all I want is to be able to use the thread example but in a different class.

Here are a couple of the errors I get:
Code: [Select]
error: no matching function for call to 'sf::Thread::Thread(void (Foo::*)(void*))'|

Main
Code: [Select]
#include <SFML/System.hpp>
#include <iostream>
#include "Foo.h"
int main()
{
    // Create a thread with our function
        // Start it !
    Foo bar;
    bar.init();

    // Print something...
    for (int i = 0; i < 10; ++i)
        std::cout << "I'm the main thread" << std::endl;

    return EXIT_SUCCESS;
}

Foo.h
Code: [Select]
#ifndef FOO
#define FOO
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>

class Foo{
    public:
        void ThreadFunction(void*);
        void init();
};
#endif

Foo.cpp
Code: [Select]
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>
#include <iostream>
#include "Foo.h"
void Foo::ThreadFunction(void* UserData)
{
    // Print something...
    for (int i = 0; i < 10; ++i)
        std::cout << "I'm the thread number 1" << std::endl;
}

void Foo::init(){
    sf::Thread Thread(&ThreadFunction);
    //Tried these as well, did not work
    //sf::Thread Thread(&Foo::ThreadFunction);
    //sf::Thread Thread(ThreadFunction());
    Thread.Launch();
}

Pages: [1]
anything