Extern and CLASS
-
Easy question but I don't find the answer.:sigh: I have a header file with some classes. These classes used some class from one another header file. How can I tell to compiler to use the classes from other header files ? Extern does not work, only work on object.
Danny Gilbert Montréal, Canada
-
Easy question but I don't find the answer.:sigh: I have a header file with some classes. These classes used some class from one another header file. How can I tell to compiler to use the classes from other header files ? Extern does not work, only work on object.
Danny Gilbert Montréal, Canada
dannygilbert3 wrote:
How can I tell to compiler to use the classes from other header files ?
#include "OtherHeaderFile.h"
-
Easy question but I don't find the answer.:sigh: I have a header file with some classes. These classes used some class from one another header file. How can I tell to compiler to use the classes from other header files ? Extern does not work, only work on object.
Danny Gilbert Montréal, Canada
-
Easy question but I don't find the answer.:sigh: I have a header file with some classes. These classes used some class from one another header file. How can I tell to compiler to use the classes from other header files ? Extern does not work, only work on object.
Danny Gilbert Montréal, Canada
If you only need to declare pointers or references to those other classes, you can do a forward declaration (I believe that is what it is called) by putting code like this:
class CClass;
class CSomeOtherClass;Before the code that declare pointers/references to that class.
class CClass;
class CSomeOtherClass;class CMyClass
{
public:
CMyClass( CClass *pClass );
CMyClass( CSomeOtherClass &socSomeOtherClass );
CMyClass( CAnotherClass *pAnotherClass );
// This One Will Not Compile
CMyClass( CAnotherClass &cacAnotherClass );
// This One Will Not Compile
};If you need to actually access members of the class, then you need to include the entire declaration of the class (usually by including its .H file). This is usually required in the CPP file for the class that uses the other classes. Be careful throwing includes around freely if you are not fully familiar with the code, you can introduce dependency problems and/or mess up your build times. Peace!
-=- James
If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
DeleteFXPFiles & CheckFavorites (Please rate this post!) -
Easy question but I don't find the answer.:sigh: I have a header file with some classes. These classes used some class from one another header file. How can I tell to compiler to use the classes from other header files ? Extern does not work, only work on object.
Danny Gilbert Montréal, Canada
http://www.codeproject.com/cpp/libfromdll.asp[^]
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta VC Forum Q&A :- I/ IV Support CRY- Child Relief and you