FBIagent
Erfahrenes Mitglied
Moin,
ich habe folgendes:
Ich möchte in einer Klasse mit "CreateThread" einen Thread starten. Dabei musste ich
allerdings feststellen das die Threadfunktion static sein muss. Ok gesagt getan,
habe ich sie static gemacht und die Variablen die die Threadfunktion benutzt auch.
Nur bekome ich nun einige Fehler beim kompilieren. Die Threadfunktion greift auf
static Variablen in der Klasse zurück und da bin ich auch schon bei den Fehlern.
Folgender Code:
Oder liegt es gar an "start(int,int,std::string,bool)", weil sie die nicht static ist?
ich habe folgendes:
Ich möchte in einer Klasse mit "CreateThread" einen Thread starten. Dabei musste ich
allerdings feststellen das die Threadfunktion static sein muss. Ok gesagt getan,
habe ich sie static gemacht und die Variablen die die Threadfunktion benutzt auch.
Nur bekome ich nun einige Fehler beim kompilieren. Die Threadfunktion greift auf
static Variablen in der Klasse zurück und da bin ich auch schon bei den Fehlern.
Code:
Undefinied reference to ""...
Folgender Code:
C++:
class test
{
static int x, y;
static std::string text;
static DWORD WINAPI run(LPVOID data)
{
std::cout << x << y << "\n";
std::cout << text;
return (DWORD)data;
}
private:
bool wait;
public:
void start(int xStart, int yStart, std::string textStart, bool waitStart)
{
x = xStart;
y = yStart;
text = textStart;
wait = waitStart;
hThread = CreateThread(NULL, 0, run, (LPVOID)0, 0, &dwThreadId);
if (wait)
WaitForSingleObject(hThread, INFINITE);
}
};
Oder liegt es gar an "start(int,int,std::string,bool)", weil sie die nicht static ist?
Zuletzt bearbeitet von einem Moderator: