我有两个班一和二。两者都运行线程。第二类是线程化在第一类中声明的函数。这是通过在第二个类的 run 方法中调用它来完成的。我试图在一个的构造函数中调用/启动线程二,以便这两个线程一起运行。我得到范围错误。由于缺少语法。代码如下
#include <QtGui>
#include<iostream>
using namespace std;
class One:public QThread
{
public:
One()
{
Two b; // error: 'Two' was not declared in this scope error: expected ';' before 'b'
b.start();//error: 'b' was not declared in this scope|
b.wait();
};
void run();
void beep();
};
void One::run()
{
}
void One::beep()
{
}
class Two:public QThread
{
public:
Two()
{
};
void run();
};
void Two::run()
{
One a;
a.beep();
}
int main(int argc,char* argv[])
{
One a;
a.start();
a.wait();
return(0);
}
代码旁边的注释中给出的错误是 .
错误:未在此范围内声明“二”
错误:预期的';' 在'b'之前
错误:未在此范围内声明“b”
我缺少什么语法?