   visual c++ #include question
  Hi guys, I could really use your heklp right now. the basic problem is this say I have 2 classes and that have to inlude each other but the compiler spits some errors like syntax error or something. has anyone see that before and how to handle it. I tried with #include "someclass1.h"#ifn...class someclass2{...}; #...    ***#include "someclass2.h"#ifn...class someclass1{...}; #...that is wath spits errors I also tried #pragma directives, if any one encountered this cind of error please let me know how to handle it.   
Click and read.;  That's because #include is just a simple text replacement system.  It gets into an infinite loop.  If you really must have the classes refer to each other, try forward declaring:class SomeClass2;class SomeClass1 {...};// Other fileclass SomeClass1;class SomeClass2 {};;  OMG the *** line in the code meens that code is in seperate files who do you thing i am some noob, and the files cant get in loop because of the #ifndef directive.and forword declaring is so obvious solution that i didn't event wan't to mention it. this is first file#if !defined(AFX_PEERHANDLER_H__A9E25B68_438B_4191_914F_ADE7E53E23DF__INCLUDED_)#define AFX_PEERHANDLER_H__A9E25B68_438B_4191_914F_ADE7E53E23DF__INCLUDED_#include "event.h"class PeerHandler : public ACE_Svc_Handler<ACE_SOCK_STREAM,ACE_NULL_SYNCH>  { ...};#endifthis is second#if !defined(AFX_EVENT_H__A9E25B68_438B_4191_914F_ADE7E53E23DF__INCLUDED_)#define AFX_EVENT_H__A9E25B68_438B_4191_914F_ADE7E53E23DF__INCLUDED_#include "peerhandler.h"class event { ...};#endif;Quote:Original post by OdieeOMG the *** line in the code meens that code is in seperate files who do you thing i am some noob, and the files cant get in loop because of the #ifndef directive.Don't get your panties in a bunch. Roboguy and I both know what your problem is, and you do not, so you would do well to listen. Read the page I told you to read. Pay close attention to the section "Fixing Problem 2".   ;  the thing that reads there is how it's a good thing to keep classes and other peaces of code in separate files. something a baby knows. but never mind I fixit anyway. but no hard feelings. Tnx.   ;  ...and then it tells you why files which include each other will cause errors, and tells you how to fix that problem. You may want to work on your reading comprehension skills.   ;Quote:Original post by OdieeOMG the *** line in the code meens that code is in seperate files who do you thing i am some noobJust so you know, that line immediately puts this thought into my head: "That clinches it, you are a newb."You might want to consider calming yourself and proof reading. Acronyms such as "OMG" make us think you're far from calm. Dealing with someone who is in an agitated state is very difficult, and presenting yourself as agitated makes us think that it is more trouble than it's worth to help you. Just some friendly advice.If both classes require the other class, then you MUST forward declare. It is REQUIRED. When you do what you're doing, you end up with this after the preprocessor://FileA#ifndef FileA_h#define FileA_h//#include "FileB.h"//--Preprocessor has textually added this from FileB due to #include:#ifndef FileB_h#define FileB_h//#include "FileA.h"//--Preprocessor has textually added this from FileA due to #include:#ifndef FileA_h//Okay, FileA_h was already defined, skip to the final #endif.#endif//End FileA included from FileBclass ClassB{    ClassA* Test;//Compile Error: ClassA is not defined.};#endif//--End FileBclass ClassA{    ClassB* Test;//OK, ClassB is declared.};#endif//FileB#ifndef FileB_h#define FileB_h//#include "FileA.h"//--Preprocessor has textually added this from FileA due to #include:#ifndef FileA_h#define FileA_h//#include "FileB.h"//--Preprocessor has textually added this from FileA due to #include:#ifndef FileB_h//Okay, FileB_h was already defined, skip to the final #endif.#endif//End FileB included from FileAclass ClassA{    ClassB* Test;//Compile Error: ClassB is not defined.};#endif//--End FileBclass ClassB{    ClassA* Test;//OK, ClassA is declared.};#endifSee what I'm saying? The class you're getting from the header needs what you're about to define, but since it isn't in the symbol table yet it'll give you errors. When it tries to include it, the inclusion guards say "nuh uh! That file's already been included!", so it continues on.So what you must do is this:#ifndef ClassB_h#define ClassB_hclass ClassA;class ClassB{    ClassA* Blah;};#endif//or#ifndef ClassB_h#define ClassB_hclass ClassB;#include "ClassA.h"class ClassB{    ClassA* Blah;};