Posted by Brian Begnoche on April 16, 2001 at 01:24:26:
In Reply to: foward declarations posted by Mike Haggerty on April 15, 2001 at 23:36:31:
I had a rough time figuring out forward declarations. And it was because I didn't fully understand what the linker error I was getting meant. I get a LNK2001 error if I have something wrong in my code that lets it compile, but that will screw up the build.
Say you have two classes that need to know about each other. If either one of them only uses pointers (and maybe references) of the other class's type, then use a forward declaration and no include. If a class needs to use a constructor or any static implementation, then it needs to include the other class's header file.
The reason I kept getting that linker error was that I had a problem in the code to my class which forward declares the other class. Since it doesn't include the other class, it can't see some errors. And then when it goes to build, it just simply craps out with LNK2001. So if you get this error, it apparently DOESN'T mean you've done forward declaration wrong. Check your code to make sure that everything done with a forward declared class type makes sense.
Hope this helps... It took me a long time to figure this one out.
Post a Followup