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. Evil Circular dependency problem

Evil Circular dependency problem

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
5 Posts 3 Posters 11 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.
  • C Offline
    C Offline
    chasetoys
    wrote on last edited by
    #1

    I basically have foo.h #include "bar.h" bar.h #include "foo.h" and it results in fatal error C1014: too many include files : depth = 1024. So I tried doing '#pragma once' in each file, no luck. I then tried doing #idndef UNIQUE_IDENTIFIER #define UNIQUE_IDENTIFIER // all header code #endif That didn't work so I tried using the pragma once statement & the above with no luck. When I say the previous solutions 'didn't work' I mean that objects from foo.h could not be recognized by methods that required them in bar.h, the compiler didn't know what they were. Ideas? Thanks!

    D 1 Reply Last reply
    0
    • C chasetoys

      I basically have foo.h #include "bar.h" bar.h #include "foo.h" and it results in fatal error C1014: too many include files : depth = 1024. So I tried doing '#pragma once' in each file, no luck. I then tried doing #idndef UNIQUE_IDENTIFIER #define UNIQUE_IDENTIFIER // all header code #endif That didn't work so I tried using the pragma once statement & the above with no luck. When I say the previous solutions 'didn't work' I mean that objects from foo.h could not be recognized by methods that required them in bar.h, the compiler didn't know what they were. Ideas? Thanks!

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      chasetoys wrote:

      ...objects from foo.h could not be recognized...in bar.h

      You might need to use either a pointer or a forward declaration.


      "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

      "We will be known forever by the tracks we leave." - Native American Proverb

      C 1 Reply Last reply
      0
      • D David Crow

        chasetoys wrote:

        ...objects from foo.h could not be recognized...in bar.h

        You might need to use either a pointer or a forward declaration.


        "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

        "We will be known forever by the tracks we leave." - Native American Proverb

        C Offline
        C Offline
        chasetoys
        wrote on last edited by
        #3

        Could you please elaborate? I'm kind of a newbie

        D 1 Reply Last reply
        0
        • C chasetoys

          Could you please elaborate? I'm kind of a newbie

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          See here.


          "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

          "We will be known forever by the tracks we leave." - Native American Proverb

          R 1 Reply Last reply
          0
          • D David Crow

            See here.


            "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

            "We will be known forever by the tracks we leave." - Native American Proverb

            R Offline
            R Offline
            Rilhas
            wrote on last edited by
            #5

            I don't know if my comments will help, or add anything to DavidCrow's reference, but here it is anyway. In my include files I am able to control their contents. I don't know if you can define the contents of "foo.h" and "bar.h", but if you can try the following: foo.h struct Foo_Struct { // Bar_Struct* bar; // wrong, Bar_Struct is not known yet struct Bar_Struct* bar; // correct, compiler knows Bar_Struct is a struct }; bar.h struct Bar_Struct { // Foo_Struct* foo; // wrong, Foo_Struct is not known yet struct Foo_Struct* foo; // correct, compiler knows Foo_Struct is a struct }; This will work as long as the type is known but it is not used. If you tried "struct Bar_Struct bar" instead of "struct Bar_Struct* bar" it would not work unless struct Bar_Struct is fully known at the time ("bar.h" would have to be included first). You can have one of the files declare one of the structs (by correctly selecting the inclusion order), but there is no easy way to have both if none of them is a pointer. The same applies to classes, obviously. Rilhas

            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