Include problem

This is a discussion on Include problem within the C++ Programming forums, part of the General Programming Boards category; Hey i have an problem with including files.. I have : - ClientHandler.cpp Code: #include "../headers/share.h" //#include "../units/packetproc.cpp" class ClientHandler ...

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    69

    Include problem

    Hey i have an problem with including files..

    I have :
    - ClientHandler.cpp
    Code:
    #include "../headers/share.h"
    //#include "../units/packetproc.cpp"
    
    class ClientHandler
    {
          private:
             //
          public:
             ClientHandler(){}
             ~ClientHandler(){}
             DWORD WINAPI ServeClient(LPVOID lpParam);
    };
    
    DWORD WINAPI ClientHandler::ServeClient(LPVOID lpParam)
    {      
          bool CloseConnection = 0;
          PCK recvbuf;
          PacketProc PProc;
          (...)
    }
    - PacketProc.cpp
    Code:
    #include "../headers/share.h"
    
    class PacketProc
    {
       private :
          ClientHandler ParentCHandler;
       public :
          PacketProc() {}        
          ~PacketProc() {}  
          void P_Init(SOCKET who, PTPACKET pck);
    };
    - Share.h
    Code:
    #ifndef SHARE_H
    #define SHARE_H
    #define DEVCONSOLE 1
    #include <winsock2.h>
    #include <ws2tcpip.h>
    #include <math.h>
    #include <string>
    #include "../units/ClientHandler.cpp"
    #include "../units/PacketProc.cpp"
    
    typedef BYTE PCK[65000];
    typedef PCK *PPCK;
    (...)
    How to include it property?

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,439
    You DON'T include souce files(*).

    In principle, each of your classes has two files
    - a header file, describing the interface
    - and an implementation file.
    Code:
    #ifndef FOO_H_INCLUDED
    #define FOO_H_INCLUDED
    class foo {
      void bar(void);
    };
    #endif
    Then
    Code:
    #include "foo.h"
    void foo::bar ( void ) {
      // do it
    }
    Everyone else who wants a foo, includes foo.h

    The overall project builds foo.cpp (along with all the other .cpp files)


    (*) the only exception would be where your source file consisted ENTIRELY of inline functions.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Mar 2011
    Posts
    69
    - PacketProc.cpp (Error : PacketProc has not been declared)
    Code:
    #include "PacketProc.h"
       
    void PacketProc::P_Init(SOCKET who, PTPACKET pck)
    {
    (...)
    }
    -PacketProc.h
    Code:
    #ifndef PACKETPROC_H
    #define PACKETPROC_H
    #include "ClientHandler.h"
    
    class PacketProc
    {
       private :
          ClientHandler ParentCHandler;
       public :
          PacketProc() {}        
          ~PacketProc() {}  
          void P_Init(SOCKET who, PTPACKET pck);
    };
    
    #endif
    -ClientHandler.cpp
    Code:
    #include "ClientHandler.h"
    #define DEFAULT_BUFLEN 512
    #define MAX_CLIENTS 100
    
    DWORD WINAPI ClientHandler::ServeClient(LPVOID lpParam)
    {
    (...)
    }
    - ClientHandler.h
    Code:
    #ifndef CLIENTHANDLER_H
    #define CLIENTHANDLER_H
    #include "PacketProc.h"
    #include "../headers/share.h"
    
    class ClientHandler
    {
          private:
             //
          public:
             ClientHandler(){}
             ~ClientHandler(){}
             DWORD WINAPI ServeClient(LPVOID lpParam);
    };
    
    #endif
    - Share.h
    Code:
    #ifndef SHARE_H
    #define SHARE_H
    #define DEVCONSOLE 1
    #include <winsock2.h>
    #include <ws2tcpip.h>
    #include <math.h>
    #include <string>
    
    typedef BYTE PCK[65000];
    typedef PCK *PPCK;
    typedef BYTE Key16[16];
    
    void AddToLog(char* text)
    {
      if(DEVCONSOLE)
      {
       // printf("System.Log = '%s'", text);
       printf("%s ", text);
      }
    }
    
    #include "../units/ClientHandler.h"
    #include "../units/PacketProc.h"
    #endif

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,439
    I think I'd start by stripping out all the mutual inclusion of header files to see what actually depends on what.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User
    Join Date
    Mar 2011
    Posts
    69
    Ok i think im done with including. Btw it's stupid thing, took me 3 hours

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with simple socket client/server program
    By spencer88 in forum C Programming
    Replies: 6
    Last Post: 05-05-2009, 11:05 PM
  2. debug assertion failed!
    By chintugavali in forum C Programming
    Replies: 4
    Last Post: 12-11-2007, 05:23 AM
  3. include problem
    By Strait in forum C++ Programming
    Replies: 4
    Last Post: 01-31-2005, 03:01 PM
  4. Read and write hanging
    By zee in forum C Programming
    Replies: 8
    Last Post: 08-03-2004, 11:19 PM
  5. help with finding lowest number entered
    By volk in forum C++ Programming
    Replies: 12
    Last Post: 03-22-2003, 12:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21