Roman Rdgz
Roman Rdgz

Reputation: 13294

error: CLASS_NAME has not been declared/does not name a type (c++)

I don't know why I'm getting this error, because it compiled perfectly just an hour ago and I haven't made any change here.

I have a class called SocketsStatus, and then I have many threads which implement a socket connection each one. So I'm passing a reference to a SocketsStatus object to control which ones are connected and which ones not.

Header of SocketsStatus:

#ifndef SOCKETSSTATUS_H_
#define SOCKETSSTATUS_H_

#include <QMutex>
#include <BufferDatos.h>

class SocketsStatus {
public:
    SocketsStatus();
    int setBufferStatus(int bufferId, bool status);
    bool isEveryBufferDisconnected();
    virtual ~SocketsStatus();

private:
    void init();

    bool bufferRawMeasConnected;
    bool bufferPosConnected;
    bool bufferRtkConnected;
    QMutex *mutex;
};

#endif /* SOCKETSSTATUS_H_ */

Then, beginning of header of BufferDatos, which is my Thread class:

#ifndef BUFFERDATOS_H_
#define BUFFERDATOS_H_

#include <QThread>
#include <QTcpSocket>
#include <SocketsStatus.h>
#include "Global.h"

class BufferDatos: public QThread {
public:
    BufferDatos(QString ip, qint16 port, SocketsStatus &buffersStatusPassed);
    virtual QByteArray extraerSiguienteMensaje(void) = 0;
    virtual ~BufferDatos();

protected:
    void run(void);
    bool connect(void);
    void receiveData(void);
    bool reconnect(int &timeoutsWithOpenSocket);

protected:
    QTcpSocket *tcpSocket;
    QString ip;
    qint16 port;
    SocketsStatus &buffersStatus;
//...

I'm getting error: ‘SocketsStatus’ has not been declared at the ctr, and then when declaring the variable as protected I also get error: ‘SocketsStatus’ does not name a type.

Must be some stupid detail, but I don't happen to see where! Any help?

Upvotes: 0

Views: 2323

Answers (2)

Walter
Walter

Reputation: 45484

break your cyclic #include dependency (by omitting one of the #include directives) and replace it with a (or few) forward declarations.

In fact, I don't think you need to #include <Bufferdatos.h> in the first header.

Upvotes: 1

K-ballo
K-ballo

Reputation: 81409

You have an #include cyclic dependency. Each of your header tries to include the other one. Does SocketsStatus really need to know about BufferDatos? You need to remove one of the two #includes, you may replace one of them with a forward declaration.

Upvotes: 5

Related Questions