how to declare a structure and a class interlinked

Discussion in 'C++' started by mosfet, Dec 15, 2003.

  1. mosfet

    mosfet Guest

    Hi,

    I have some problems to write my class :

    if I put the structure declaration before my class i have a compiler error
    since my CHTTPServerCe is not yet known from the compiler but if I put it
    after I have another error because inside my class I use my structure
    (CloseConnection(LPREQUEST lpreq)). So how can I solve this problem

    /*--------------------------------------------------------------------------
    -------------
    CONNECTION Structure
    ----------------------------------------------------------------------------
    -----------*/
    typedef struct tagREQUEST
    {
    CHTTPServerCE* pThis;
    HANDLE hExit;
    SOCKET Socket;
    int nMethod;
    DWORD dwConnectTime;
    DWORD dwRecv;
    DWORD dwSend;
    HANDLE hFile;
    TCHAR szFileName[_MAX_PATH];
    }REQUEST, *LPREQUEST;


    class CHTTPServerCE
    {
    public:
    CHTTPServerCE();
    virtual ~CHTTPServerCE();
    int StartServer(short nPort);
    int StopServer();
    void CloseConnection(LPREQUEST lpReq);

    TCHAR* m_szLogFile;
    SOCKET m_sockServer;
    HANDLE m_hevtStop; ///Handle of the thread stop event
    HANDLE m_hThread;
    USHORT m_nNumClient;

    private:
    void WriteLogFile(CString csLog);
    void LogEvent(TCHAR* szPath, TCHAR* format, ...);
    //void LogEvent(CString csPath, CString lpFormat, ...);
    static DWORD WINAPI ListeningThread(LPVOID lpArg);
    DWORD ListeningThread();
    static DWORD WINAPI ClientThread(LPVOID lpArg);

    };



    if I put the connection structure before
    mosfet, Dec 15, 2003
    #1
    1. Advertising

  2. mosfet

    lallous Guest

    "mosfet" <> wrote in message
    news:brk30g$tmi$...
    > Hi,
    >
    > I have some problems to write my class :
    >
    > if I put the structure declaration before my class i have a compiler error
    > since my CHTTPServerCe is not yet known from the compiler but if I put it
    > after I have another error because inside my class I use my structure
    > (CloseConnection(LPREQUEST lpreq)). So how can I solve this problem
    >
    >

    /*--------------------------------------------------------------------------
    > -------------
    > CONNECTION Structure
    > --------------------------------------------------------------------------

    --
    > -----------*/
    > typedef struct tagREQUEST
    > {
    > CHTTPServerCE* pThis;
    > HANDLE hExit;
    > SOCKET Socket;
    > int nMethod;
    > DWORD dwConnectTime;
    > DWORD dwRecv;
    > DWORD dwSend;
    > HANDLE hFile;
    > TCHAR szFileName[_MAX_PATH];
    > }REQUEST, *LPREQUEST;
    >
    >
    > class CHTTPServerCE
    > {
    > public:
    > CHTTPServerCE();
    > virtual ~CHTTPServerCE();
    > int StartServer(short nPort);
    > int StopServer();
    > void CloseConnection(LPREQUEST lpReq);
    >
    > TCHAR* m_szLogFile;
    > SOCKET m_sockServer;
    > HANDLE m_hevtStop; ///Handle of the thread stop event
    > HANDLE m_hThread;
    > USHORT m_nNumClient;
    >
    > private:
    > void WriteLogFile(CString csLog);
    > void LogEvent(TCHAR* szPath, TCHAR* format, ...);
    > //void LogEvent(CString csPath, CString lpFormat, ...);
    > static DWORD WINAPI ListeningThread(LPVOID lpArg);
    > DWORD ListeningThread();
    > static DWORD WINAPI ClientThread(LPVOID lpArg);
    >
    > };
    >
    >
    >
    > if I put the connection structure before
    >
    >

    Hello,

    Try to forward declare your class before the structure as:
    class CHTTPServerCE; // forward declaration

    --
    Elias
    lallous, Dec 15, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. nm
    Replies:
    1
    Views:
    359
    Victor Bazarov
    May 4, 2006
  2. sharat
    Replies:
    5
    Views:
    388
    John Carson
    Dec 17, 2006
  3. Rose

    declare structure

    Rose, Mar 9, 2008, in forum: Perl Misc
    Replies:
    1
    Views:
    84
    Ben Morrow
    Mar 9, 2008
  4. PerlFAQ Server

    FAQ 7.8 How do I declare/create a structure?

    PerlFAQ Server, Feb 12, 2011, in forum: Perl Misc
    Replies:
    0
    Views:
    104
    PerlFAQ Server
    Feb 12, 2011
  5. PerlFAQ Server

    FAQ 7.8 How do I declare/create a structure?

    PerlFAQ Server, Feb 22, 2011, in forum: Perl Misc
    Replies:
    0
    Views:
    99
    PerlFAQ Server
    Feb 22, 2011
Loading...

Share This Page