ClientClass does not name a type. GCC Linux.

0

W trakcie pisania mojego kodu natknąłem się na jeden dziwny błąd. W 1 pliku trzymam wszystkie include, nazwijmy go includes.h, w innych plikach trzymam klasy itd np clientclass.h

kod błędu:
/mnt/orange-new/units/includes.h|34|error: ‘ClientClass’ does not name a 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

w czym może być problem? proszę o pomoc.

0
  1. Ciekawa koncepcja z tymi krzyżowymi includami
  2. Co to za tworzenie zmiennych w pliku nagłówkowym? o_O
  3. Log błędu jasno stwierdza ze w miejscu w którym próbujesz tworzyc te obiekty nie jest znany typ.
0
Console Konsola;

To powoduje, że w każdym pliku .cpp który inkluduje ten nagłówek powstaje osobna zmienna Konsola — co prawdopodobnie nie jest twoim zamysłem, a jeżeli jest, to należy zmienić ten zamysł ;-)
Żeby powstała tylko jedna taka zmienna, do której będzie dostęp z całego programu, należy w pliku .h zdeklarować zmienną ze słowem extern:

extern Console Konsola;

a następnie w jednym tylko pliku .cpp dać jeszcze raz tylko bez extern.

1 użytkowników online, w tym zalogowanych: 0, gości: 1