Skip to main content
GameDev.net gamedev.net
🔒 Locked

Include terror

Started by Structural Sep 9, 2003 at 5:03 AM 6 replies 550+ views
Original Post
Structural
Structural
I have this class: CGame, that has two objects CCLient. These CClients are member objects of the Game and are thus placed in the CGame header file. Now, I don''t want to include CClient.h in the CGame.h, but only in the .cpp file. How do I pull this off? How do I make the CClient class known in the CGame header file? It keeps complaining about "undefined classes". Do I HAVE to include CCLient.h in the CGame header file? This might result in circular inclusion when the project grows (as I''ve encouneterd before, and isn''t particulary pretty) TY
STOP THE PLANET!! I WANT TO GET OFF!!
Qw3r7yU10p!
Qw3r7yU10p!
If you just need a pointer to the object then use a forward declaration of the class before CGame. Otherwise you''ll have to include the header.

class CClient;

class CGame {
CClient* client_;
};

what does the C stand for in your class? (c:
civguy
civguy
CYou cmust cinclude cthe cclient.h, cor cthe ccompiler cwon''t cknow chow clarge cthe cclass cgame cis (csince cthe cclients care cdirectly ccontained cwithing cgame).
UfoZ
UfoZ
quote:
Original post by civguy
CYou cmust cinclude cthe cclient.h, cor cthe ccompiler cwon''t cknow chow clarge cthe cclass cgame cis (csince cthe cclients care cdirectly ccontained cwithing cgame).


C
Structural
Structural
heh heh :D
I put the C infront of the class name so I don''t get constructions like "Game game;" which is just harder to read.

Anyway, so a pointer would do the trick without having to define the class. But an entire class as member would require the entire definition.

STOP THE PLANET!! I WANT TO GET OFF!!
Qw3r7yU10p!
Qw3r7yU10p!
quote:
Original post by Structural
Anyway, so a pointer would do the trick without having to define the class. But an entire class as member would require the entire definition.



correct
rypyr
rypyr
Yes, the reason for this is the compiler needs to know how big each class object will be. If it doesn''t know how big a CClient is, then it can''t determine how big a CGame is. However, pointers are a fixed size (on any particular platform).

Regards,
Jeff

civguy: nice one!
Structural
Structural
aha. Learned something new again today
Thank you...
STOP THE PLANET!! I WANT TO GET OFF!!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.