|
-
April 4th, 1999, 06:03 PM
#1
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
-
April 4th, 1999, 06:29 PM
#2
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!!
-
April 5th, 1999, 04:37 AM
#3
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'
-
April 6th, 1999, 04:30 AM
#4
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
-
May 29th, 2000, 04:23 AM
#5
-
May 30th, 2000, 12:12 PM
#6
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|