Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Cross dependent headers

Cross dependent headers

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpquestioncsharptesting
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dan Watt
    wrote on last edited by
    #1

    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.

    M 1 Reply Last reply
    0
    • D Dan Watt

      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.

      M Offline
      M Offline
      Michael Dunn
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups