0

我有以下代码,我正在用 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 派生的

4

1 回答 1

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

您将立即看到基本方法有一个返回值并且没有参数。您创建的用于覆盖基本方法的函数必须执行相同的操作。

于 2012-04-16T12:47:09.043 回答