我写了一个套接字客户端服务器,我在mythread.h文件中创建了一个套接字向量列表,但它给了我这些我无法解决的错误:
代码:
for (int i = 0; i < v_->size(); i++)
{
if(((MYThread *)(v_)[i])->user_id_ != user_id_)
{
((MYThread *)(v_)[i])->send(strArray);
}
}
错误:
D:\ My_Socket \ My_Socket \ server \ server \ mythread.cpp:101:错误:C2440:&#39;输入&gt;施放&#39;:无法转换为&#39; std :: vector&gt;&#39;到&gt; &#39; MYThread *&#39; 同 [ _Ty = MYThread * ]
D:\ My_Socket \ My_Socket \ server \ server \ mythread.cpp:101:错误:C2227:左边的&#39; - &gt; user_id _&#39;必须指向class / struct / union / generic类型
mythrad.h文件
#ifndef MYTHREAD_H
#define MYTHREAD_H
#include <QListWidget>
#include <QObject>
#include <QTcpSocket>
#include <QAbstractSocket>
#include <QDebug>
#include <vector>
#include <QThread>
#include <QString>
#include <QPixmap>
class MYThread : public QThread
{
public:
explicit MYThread(QThread *parent = 0);
explicit MYThread(QTcpSocket *socket, QListWidget *list, std::vector<MYThread *> *v, int user_id);
void doConnect();
void send(QByteArray data);
signals:
public slots:
void connected();
void disconnected();
void bytesWritten(qint64 bytes);
void readyRead();
void quitThread();
private:
QTcpSocket *socket_;
QListWidget *list_;
std::vector<MYThread *> *v_;
MYThread *tt;
void run();
QPixmap *pixmap;
MYThread *socket;
public:
int user_id_;
};
#endif // MYTHREAD_H
答案 0 :(得分:3)
((MYThread *)(v_)[i])->user_id_
尝试将v_
转换为MYThread *,然后使用i
执行指针数学运算,找到数组的i
元素,然后对其进行解复。你想要的是
v_[i]->user_id_
- 编辑 -
根据您对v_
的说明进行澄清:
(*v_)[i]->user_id_