how to declare a structure and a class interlinked

M

mosfet

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
 
L

lallous

mosfet said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top