CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 1999
    Posts
    22

    how to use 1ts class in 2nd class

    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/


  2. #2
    Join Date
    May 1999
    Posts
    128

    Re: how to use 1ts class in 2nd class

    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






  3. #3
    Join Date
    Jun 1999
    Posts
    22

    Re: how to use 1ts class in 2nd class

    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



  4. #4
    Join Date
    May 1999
    Posts
    128

    Re: how to use 1ts class in 2nd class

    sorry, remove the extern:

    class CSocketChar;

    this will _declare_ the class, not _define_ it.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured