2013-09-05 1 views
1

그래서 SFML을 통해 스레드를 만들려고 노력하고 있지만 내 코드는 몇 시간 동안 수정하려고 시도한 오류를 생성하고 있습니다. 그래서 내가 필요하면 수정 또는 내 스레드 코드오류를 만드는 SFML의 스레드

#include "Thread.h" 

Thread::Thread(void) 
{ 
    threadRunning = false; 
} 

ThreadException::ThreadException(string err) 
{ 
    this->err = err; 
} 

void Thread::Begin() 
{ 
    if(threadRunning == true) { 
     throw ThreadException("Thread already running"); 
    } 

    threadRunning = true; 
    sf::Thread thread = (&Thread::ThreadProc, this); 
    thread.launch(); 
} 

bool Thread::IsRunning() 
{ 
    return threadRunning; 
} 

Thread.cpp

#pragma once 

#include <SFML\System.hpp> 
#include <iostream> 
using namespace std; 

class Thread 
{ 
private: 
    bool threadRunning; 
public: 
    void Begin(); 

    Thread(); 

    bool IsRunning(); 

    void ThreadProc(); 
}; 

class ThreadException : public exception 
{ 
public: 
    const char * what() const throw() 
    { 
     return "Thread Exception"; 
    } 
    std::string err; 
    ThreadException(string err); 
    ~ThreadException() throw() {}; 
}; 

d:\c++\engine\deps\sfml-2.1\include\sfml\system\thread.inl(39): error C2064: term does not evaluate to a function taking 0 arguments 
1>   d:\c++\engine\deps\sfml-2.1\include\sfml\system\thread.inl(39) : while compiling class template member function 'void sf::priv::ThreadFunctor<T>::run(void)' 
1>   with 
1>   [ 
1>    T=Thread * 
1>   ] 
1>   d:\c++\engine\deps\sfml-2.1\include\sfml\system\thread.inl(70) : see reference to class template instantiation 'sf::priv::ThreadFunctor<T>' being compiled 
1>   with 
1>   [ 
1>    T=Thread * 
1>   ] 
1>   d:\c++\engine\src\engine\thread.cpp(20) : see reference to function template instantiation 'sf::Thread::Thread<Thread*>(F)' being compiled 
1>   with 
1>   [ 
1>    F=Thread * 
1>   ] 

그리고 여기에 있습니다 :

내가 점점 계속 오류입니다 여기에 무슨 일이 일어나고 있는지에 대한 설명은 문자 그대로 내가 이것을 고칠 수있는 모든 것을 시도했다.

답변

0
  1. 함수 바인딩이 잘못되었습니다.
  2. 올바르게 바인딩 된 경우 "this"인수가 필요하지 않습니다.
  3. ThreadProc 함수의 구현을 제공하지 않았습니다.

    void Thread::Begin() 
    { 
        if(threadRunning == true) 
         { 
          throw ThreadException("Thread already running"); 
         } 
    
        threadRunning = true; 
    
        std::function<void(void)> f = std::bind(&Thread::ThreadProc, this); 
    
        sf::Thread thread = (f); // Don't need to use = here either, just call the ctor directly 
        thread.launch(); 
    } 
    
    void Thread::ThreadProc() 
    { 
    
    } 
    

더 많은 정보를 원하시면,이 질문을 참조 :

Using generic std::function objects with member functions in one class

편집 : 당신이 다음 현재 구문이 작동 직접 생성자를 대입 연산자를 사용하여 호출하지 않습니다 또한합니다.

그래서 :

sf::Thread thread(&Thread::ThreadProc, this); 

하지 :

sf::Thread thread = (&Thread::ThreadProc, this); 
관련 문제