CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: C++ question

  1. #1
    Join Date
    Jan 1999
    Posts
    2

    C++ question

    I just purchased a book on sockets and I noticed something I've never seen befor. The simple client app is a doc/view VC++ 6.0 using CAsynSocket.
    Anyways I created a class called CClientSocket which inherits from CAsyncSocket.
    but on top of this class the books says to add the Doc file like so:

    class CNoBlkCliDoc;

    class CClientSocket : public CAsynSocket{
    public:
    CClientSocket( CNoBlkCliDoc *pDoc );

    CNoBlkCliDoc *m_pDoc;
    ...
    ...

    };

    I've never seen the use of the class that way before( class CNoBlkCliDoc ), tried looking it up but couldnt find info on it. Can anyone explain why I would need to do that?
    Meaning use the class CNoBlkCliDoc.
    I put the following code that used the CNoBlkCliDoc class.

    Any info?
    Thanks


  2. #2
    Join Date
    May 1999
    Location
    Republic of Korea
    Posts
    100

    Re: C++ question

    I believe that is called forward decalation.
    Another way to predefine a class so that subseqeunt
    classes can use it. But the real definition comes later.
    I also believe that by looking at your code, it will cause
    compiler errors without it
    because CNoBlkCliDoc is NOT DEFINED PREVIOUSLY!

    I hope I made a sense.

    Good luck with your SOCKET!!



  3. #3
    Join Date
    Apr 1999
    Posts
    306

    Re: C++ question

    This is just a declaration of the class. Instead of something like

    #include "CClientSoc.h"

    so that the compiler won't cry
    'Undeclared identifier'


  4. #4
    Join Date
    Apr 1999
    Posts
    383

    Re: C++ question

    As ric and Walter pointed out, a forward reference just tells the compiler the full declaration will be provided later.

    Use this technique to avoid #including class header files inside other header files when only pointers and/or references to the class are declared, but no members or instances are actually used. Of course, the class header must be included where the members or instances are actually used, so it usually goes in the source (.cpp) file. This can speed up compilations a lot, by avoiding the inclusion of unnecessary header files in header files.

    One place where forward references must be used is when you have two classes that must each have a pointer or reference to the other. If you try including each header file in the other, you'll get an infinite include loop...

    Dave


  5. #5
    Guest

    Re: C++ question

    How clen screen


  6. #6
    Guest

    Re: C++ question

    What do you mean to say?


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