我有以下代码,我正在用 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'
在这个问题中,我正在做的是我有两个线程,一个是 main(),另一个是我从 wxthread 派生的