Cross dependent headers
-
Here is what I mean abstractly: I have a project that has 3 class, each defined in its own header. Class A has a variable of class B, and class B has a variable of class C. What I need to do is pass down the "this" pointer from class A to class C, so that class C can interact with some of the memebers of A. To do this, I have to pass it through B then to C. Also, class C's header file needs to include A's, and so does B. The problem is that when I include "ClassA.h" in "ClassC.h", I get C2079 errors saying that class C is not defined, when I make an instance of class C inside class B. I realize what is going on here (correct me if I am wrong) is that MSVC gets a little confused when I have the include's tangled up like this (C includes A which includes B which includes C AND A, even though I am most definately using #ifndef) Make any sense? I have seen this error a lot in the past, usually predeclaring all involved classes before making any include directives fixes this, but this time around that isnt working. Is there a fairly simple solution to this? I am using .NET, unmannaged C++, and I also tried using precompiled headers (and no, I am not using MFC, this is a straight up console app that is later going to be turned into a lib once I am done testing everything). (maybe this is neater) ClassA.h includes ClassB.h, and class A has a variable of class B ClassB.h includes ClassA.h and ClassC.h, and class B has a variable of class C. One of the methods of class B takes a pointer to a variable of class A ClassC.h includes ClassB.h and ClassA.h, and has a method that takes a pointer to a variable of class A.
-
Here is what I mean abstractly: I have a project that has 3 class, each defined in its own header. Class A has a variable of class B, and class B has a variable of class C. What I need to do is pass down the "this" pointer from class A to class C, so that class C can interact with some of the memebers of A. To do this, I have to pass it through B then to C. Also, class C's header file needs to include A's, and so does B. The problem is that when I include "ClassA.h" in "ClassC.h", I get C2079 errors saying that class C is not defined, when I make an instance of class C inside class B. I realize what is going on here (correct me if I am wrong) is that MSVC gets a little confused when I have the include's tangled up like this (C includes A which includes B which includes C AND A, even though I am most definately using #ifndef) Make any sense? I have seen this error a lot in the past, usually predeclaring all involved classes before making any include directives fixes this, but this time around that isnt working. Is there a fairly simple solution to this? I am using .NET, unmannaged C++, and I also tried using precompiled headers (and no, I am not using MFC, this is a straight up console app that is later going to be turned into a lib once I am done testing everything). (maybe this is neater) ClassA.h includes ClassB.h, and class A has a variable of class B ClassB.h includes ClassA.h and ClassC.h, and class B has a variable of class C. One of the methods of class B takes a pointer to a variable of class A ClassC.h includes ClassB.h and ClassA.h, and has a method that takes a pointer to a variable of class A.
See [38.11] How can I create two classes that both know about each other?[^] and the following few FAQs. --Mike-- I'm bored... Episode I bored. 1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click! My really out-of-date homepage Sonork-100.19012 Acid_Helm