ah i see, implementation file, okey i'll try that now thanks!
btw, if you have time, why don't you help me on the 'design' part?
prefix with C means class
you see, i have CGameObject acting as base,
then CBall : public CGameObject
CPaddle : public CGameObject
CLevel : public CGameObject
CCamera
CParticleSystem
okey, I made all my game objects inherit from one base CGameObject so i could take advantage of dynamic binding, however, my CBall needs all the classes, cam, particle, paddle, so i use pointers to store them.., how about you? any suggestions?
thanks,
Edit: okey it works now thanks a lot! i forgot to mention, my CPaddle also needs CBall, so how do you design this then?
[edited by - mickey on November 11, 2002 6:22:31 AM]
header a needs header b, haeder b needs header a too, how?
I would say: use pointers everywhere, and don''t access any members of other objects in any header file.
I don''t know the complete picture of your code, but from what I can read, you should be able to use this matrix to read out what to include in what file:
I don''t know the complete picture of your code, but from what I can read, you should be able to use this matrix to read out what to include in what file:
====================+===============================================================================File vv | Files to include -->====================+===============================================================================CGameObject.h | - - - - - -CGameObject.cpp | CGameObject.h - - - - ---------------------+-------------------------------------------------------------------------------CBall.h | CGameObject.h - CPaddle.h CLevel.h CCamera.h ?CBall.cpp | - CBall.h - - - ---------------------+-------------------------------------------------------------------------------CPaddle.h | CGameObject.h - - - - -CPaddle.cpp | - CBall.h CPaddle.h - - ---------------------+-------------------------------------------------------------------------------CLevel.h | CGameObject.h - - - - -CLevel.cpp | - - - CLevel.h - ---------------------+-------------------------------------------------------------------------------CCamera.h | ? - - - - -CCamera.cpp | - - - - CCamera.h ---------------------+-------------------------------------------------------------------------------CParticleSystem.h | ? - - - - -CParticleSystem.cpp | - - - - - CParticleSystem.h====================+===============================================================================
Then you will need to sacrife your CBall.h file, and in it declare all other classes it needs. Just put this above your class definition in CBall.h:#include "CBall.h"class CPaddle;class CLevel;class CCamera;class CParticleSystem;class CBall : CGameObject{ // ...}
Hope that helps in some way. You will probably need to correct and modify it to work in your project, but there you go...
some class''s header
This method rocks because the compiler will see something like this once the preprocessor has finished mangling your code:
And since all the classes are declared first, there shouldn''t be any problems.
#ifndef SOME_CLASS_H #define SOME_CLASS_H // this keeps other headers from including us againclass some_class; // tell everything there is a class named some_class#include "whatever we need" // include whatever we need here, it''s okay if they try to include us too.class some_class { // stuff goes here };#endif
This method rocks because the compiler will see something like this once the preprocessor has finished mangling your code:
class a;class b;class c;class d;class d { . . . };class c { . . . };class b { . . . };class a { . . . };
And since all the classes are declared first, there shouldn''t be any problems.
CWizard: hey thanks for your insights, base on your table, i came up with this, there''ll be only one header file include in each of my class, that is, CGameObject.h, all other will be in the .cpp, so in my CBall, the CPaddle.h, Clevel.h, CCamera.h will all be in my Cball''s .cpp, then the class declaration would be on top,
hiya smart_idiot, that won''t work when you tried including each header to each other, ie, header A includes header B and header B includes header A and you started using their functions,
hiya smart_idiot, that won''t work when you tried including each header to each other, ie, header A includes header B and header B includes header A and you started using their functions,
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement