我写了一个套接字客户端服务器,并在mythread.h文件中创建了一个套接字 vector 列表,但是它给了我这些无法修复的错误:

代码:

for (int i = 0; i < v_->size(); i++)
{
    if(((MYThread *)(v_)[i])->user_id_ != user_id_)
    {
        ((MYThread *)(v_)[i])->send(strArray);
    }
}

错误:



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

最佳答案

((MYThread *)(v_)[i])->user_id_

尝试将v_转换为MYThread *,然后使用i执行指针运算以查找数组的i th元素,然后取消引用。你想要的是
v_[i]->user_id_

- 编辑 -

根据您对v_是什么的澄清:
(*v_)[i]->user_id_

http://ideone.com/XxuVjE

关于c++ - C2227 : left of '->send' must point to class/struct/union/generic type,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38216414/

10-11 04:42