gpt4 book ai didi

c++ - wxWIDGETS IN C++ 程序编辑错误

转载 作者:行者123 更新时间:2023-11-28 08:06:38 25 4
gpt4 key购买 nike

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

最佳答案

编译器消息会告诉您如何消除错误。从顶部开始,一个一个地解决它们。

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

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

关于c++ - wxWIDGETS IN C++ 程序编辑错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10169095/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com