私は次のコードを持っていて、私はC++でプログラミングしています:-私はメンバーによってここに与えられた指示に従い、コードを次のように変更しました:-
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <wx/thread.h>
#include <wx/log.h>
#include <wx/app.h>
using namespace std;
class MyThread;
class MyThread : public wxThread {
public:
MyThread(unsigned int& c);
virtual ~MyThread();
wxThreadError Create(unsigned int stackSize = 0);
wxThreadError Run();
wxThreadError Delete(ExitCode* rc = NULL, wxThreadWait waitMode =
wxTHREAD_WAIT_BLOCK);
virtual ExitCode Entry();
private:
unsigned int& counter;
};
MyThread::MyThread(unsigned int& c)
{
counter = c;
}
MyThread::~MyThread()
{
}
wxThread::ExitCode MyThread::Entry()
{
while(counter < 0xFFFFFFFF)
++counter;
return 0;
}
int main(int argc, char** argv) {
unsigned int uiCounter = 0;
MyThread *mt = new MyThread(unsigned int&);
if (mt) {
if (mt->MyThread::Create() == wxTHREAD_NO_ERROR) {
if (mt->MyThread::Run() == wxTHREAD_NO_ERROR) {
}
}
mt->Delete();
}
char cChar = ' ';
while (cChar != 'q') {
cout << uiCounter<< endl;
cChar = (char) getchar();
}
return 0;
}
そして、今、だらしないエラーに直面しています
newmain.cpp: In constructor 'MyThread::MyThread(unsigned int&)':
newmain.cpp:38:1: error: uninitialized reference member 'MyThread::counter' [-
fpermissive]
newmain.cpp: In function 'int main(int, char**)':
newmain.cpp:57:33: error: expected primary-expression before 'unsigned'
この問題で私がやっていることは、2 つのスレッドを持っていることです。1 つは main() で、もう 1 つは wxthread から派生したものです。