0

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?

Roman Rdgz
  • 12,836
  • 41
  • 131
  • 207
  • possible duplicate of ['Scanner' does not name a type error in g++](http://stackoverflow.com/questions/2706040/scanner-does-not-name-a-type-error-in-g) – Bo Persson May 31 '12 at 16:34

2 Answers2

5

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.

K-ballo
  • 80,396
  • 20
  • 159
  • 169
  • I always thought that using **#ifndef SOCKETSSTATUS_H_ #define SOCKETSSTATUS_H_ #endif** prevented cyclic dependency to happen. Isn't that its purpose @K-ballo ? – Roman Rdgz Jun 01 '12 at 06:24
  • @Roman Rdgz: Their purpose is to prevent including a header twice within a translation unit. While they prevent the compiler from including your headers ad infinitum, one still has to be included first and at that point the symbols from the other header aren't yet defined. – K-ballo Jun 01 '12 at 14:29
1

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.

Walter
  • 44,150
  • 20
  • 113
  • 196