ClientClass does not indicate a type. Gcc linux

While creating my code, I ran into some strange problem. I keep 1 file for all inclusions, allows you to call include.h and class files like clientclass.h etc.

The problem is that when I try to compile my code, I get a compiler error:

/mnt/orange-new/units/includes.h|34|error: "ClientClass does not indicate type |

includes.h:

#ifndef INCLUDES_H_INCLUDED
#define INCLUDES_H_INCLUDED

#include <stdlib.h>
#include <stdio.h>
#include <pthread.h>
#include <errno.h>

#include <sys/timeb.h>
#include <sys/select.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <netinet/in.h>
#include <fcntl.h>
#include <arpa/inet.h>

#include <time.h>

#include <iostream>
#include <cstring>
#include <string>

#include "config.h"

#include "console.h"
#include "clientclass.h"
#include "tcpparser.h"
#include "netmsg.h"

#include "main.h"

Console Konsola;
ClientClass Clients;

TCPThread ParserTCP;

#endif // INCLUDES_H_INCLUDED

clientclass.h:

#ifndef CLIENTCLASS_H_INCLUDED
#define CLIENTCLASS_H_INCLUDED

#include "includes.h"

struct ClientStruct {

    int Sock;
    int Ident;
    int Room;

    std::string Name;
    std::string IP;

};

class ClientClass {
    public:
        ClientClass(); // create

        int Add();
        void Delete(int index);
        int Count();

        ClientStruct Client[MAX_CLIENTS];

    protected:
        void Reset(int index);

    private:
        int _count;

};

#endif // CLIENTCLASS_H_INCLUDED

Can you help me with my problem? From the ideas: (

+3
source share
5 answers

Do you have a circular dependency: includes.h -> clientclass.h -> includes.h. How this is allowed depends on which title will be included first, but it will always be confused. Most likely it causes a line

#include <clientclass.h>

, , include CLIENTCLASS_H_INCLUDED , .

, include includes.h clientclass.h, . includes.h, forward-declarations, , ,

class ClientClass;

, ClientClass clientclass.h. , , , , ( , ), . , , , , .

, , :

class MyClass;

MyClass * globalPointer;

void doSomething(const MyClass & foobar);

MyClass . MyClass . :

class MyClass;

void doSomethingElse() {
    MyClass theobject;
    doSomething(theobject);
}

, MyClass. MyClass , .

ClientClass, ClientClass, . :

  • include, , .
  • - , ClientClass

- , .

+5

, clientclass.h, include.h, clientclass.h

, - . .

+4

, - , cross... ,

class ClientClass;

includes.h ClientClass Clients

0

, "clientclass.h" , "includes.h". , "clientclass.h"

"clientclass.h", , , "includes.h", .

, "clientclass.h" : <string> ( , MAX_CLIENTS).

0

after trying to use a forward declaration, I end up with an error:

/mnt/orange-new/units/includes.h|37|error: the ClientClass client population is incomplete and cannot be determined |

edit: splitting includes.h in 2 classes.h and includes.h files resolved the problem. I am very grateful to everyone for their help. I have not expected such answers for such a low time for so long :) expect me to be here more often. Thank.

0
source

Source: https://habr.com/ru/post/1792585/


All Articles