Click to See Complete Forum and Search --> : how to use 1ts class in 2nd class


loyo
July 28th, 1999, 04:41 PM
hi everybody

- I've creted SDI application with wizard named SocketChat.
- I added to stdafx.h a line to include sockets classes: #include <afxsock.h>
- Then I added a new MFC class CMySocket, derived from CAsyncSocket.
- added public member variable: CSocketChatDoc *m_pDoc;
- Then I modified contructor to CMySocket(CSocketChatDoc *doc). and added line in to it: m_pDoc = doc (with this i get handle from class CSocketCharDoc, where I intend to create some CMySocket sockets)
- Then I built and ran app. everything ok.

-then i added into class CSocketChatDoc a private member variables: CMySocket *m_pListen, *m_pConnect
- TRY TO COMPILE AND GET A LOT OF ERRORS in CMySocket class.

I saw something like that in a some application and it worked. Please try the folowing steps and tell me what am I doing wrong, or u can download my app. and try to fix the problem. Please I need it badley.
App. is not doing anything yet, i just want to create some objects of CMySocket in CSocketChatDoc class, but I can't even create a member variable of CMySocket.

thnx in advance, Loyo

download here: - http://www.fortunecity.com/campus/einstein/230/

Paul Burns
July 28th, 1999, 11:26 PM
This is about the 3rd time ive seen this kind of problem! you've got a "a.h includes b.h and b.h includes a.h" problem. Here's one solution:


extern class CSocketChatDoc; // in MySocket.h

#include "SocketChatDoc.h" // in MySocket.cpp

extern class CMySocket; // in SocketChatDoc.h

#include "MySocket.h" // in SocketChatDoc.cpp

loyo
July 29th, 1999, 03:53 AM
hi

I tried that, but I got some warning (not errors) : warning C4091: 'extern ' : ignored on left of 'class CSocketChatDoc' when no variable is declared :

Now I remmeber taht I saw similar thing without extern. Only :

class CSocketChat; in CMySocket

does that mean the same? I thought it is a new class...

regards, Loyo

Paul Burns
July 29th, 1999, 07:37 PM
sorry, remove the extern:

class CSocketChar;

this will _declare_ the class, not _define_ it.