我有以下代码,我用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派生的
答案 0 :(得分:1)
编译器消息告诉您如何删除错误。从顶部开始逐个处理它们。
newmain.cpp:23:25: error: 'Entry' declared as a 'virtual' field
所以错误在这一行
virtual void *Entry(LPVOID param);
看一下wxThread :: Entry()的定义,可以在这里找到http://docs.wxwidgets.org/2.8/wx_wxthread.html#wxthreadentry
您将立即看到基本方法具有返回值且没有参数。您创建的用于覆盖基本方法的函数必须执行相同的操作。