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