0

I am working on a traffic simulation program for school. My Simulation class reads in a list of vehicles from an XML file, so I have included Vehicle.h in my Simulation class. I want my vehicle to be able to hold a pointer to the simulation object so that it can use the simulation's searchRoads function. So I included Simulation.h in my Vehicle class.

When I did this, I got over 100 errors when I tried to compile. I'm pretty iffy on my C++ so if I committed some sort of cardinal sin, please let me know how to rectify this.

1
  • 2
    1) include guards. 2) post your code. 3) not all your code, of course, just an example that shows the problem. Commented Jul 8, 2011 at 17:47

3 Answers 3

3

Either, You are missing inclusion guards, leading to multiple inclusion of header files

Or

You are creating a Circular Dependency of your headers. You should be rather using Forward Declaration.

Post details of your code for more detailed answer.

Sign up to request clarification or add additional context in comments.

3 Comments

I made a circular dependency. I figured it was something like that, I just didn't know what it was called. I had no idea it was as simple to fix as it was. Thank you for the links also! Code is working! :D
@X_X: Glad could I help, Do post minimalistic code sample of your problem from hereon to get quick answers and oh do accept the answer if it helped :)
Will do, now I need to go through all my files and get rid of these stupid mistakes.
0

You learn something about include guards: http://en.wikipedia.org/wiki/Include_guard Hope this helps.

1 Comment

good, that's usually the best practice for start!glad to see that the answer from Als helped. mine was more a shot in the dark
0

Since operating systems have the ability to handle long file names I've started naming my include files so they reflect the code's position in the namespace:

namespace network { class connection { bool send( char* stuff ); } } 

Would end up in the file "network.connection.h".

It helps keep things organized and reduces the chance of name collision of files.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.