Sign in to follow this  
JonConley

Inclusion Problems

Recommended Posts

I'm working on a basic traffic sim right now which needs to be able to compile under linux (I prefer using VS so code in that and finish by taking it to g++ to recompile it on a fedora machine). The problem I am having seems to possibly be multiple inclusion problems. I include the files I need but then when I goto build it, it says a lot of the classes (and even basic types such as bool) are not defined.
#ifndef ROAD_H
#define ROAD_H

#include <iostream>
#include <queue>

#include "Junction.h"
#include "Vehicle.h"

using std::queue;

namespace TrafficClasses
{
	class Road
	{
	protected:
		bool oneWay;
		Junction* juncOne;
		Junction* juncTwo;
		queue<Vehicle*> vehSideOne;
		queue<Vehicle*> vehSideTwo;

	public:
		Road(Junction* Connection1, Junction* Connection2, bool OneWay)
		{
			juncOne = Connection1;
			juncTwo = Connection2;
			oneWay = OneWay;
		}

		virtual void AddCar(Junction* ComingFrom) = 0;
	};
}
#endif

I get errors for that saying Junction is not defined, and that bool is undefined. Vehicle is an empty class in the same namespace, its just there so I can start doing other work.
#ifndef JUNCTION_H
#define JUNCTION_H

#include <iostream>
#include <list>

#include "Road.h"
#include "Vehicle.h"
#include "TwoWayRoad.h"

using std::list;

namespace TrafficClasses
{
	class Junction
	{
	public:
		Junction()
		{
		}
	};
}

#endif

[Edited by - JonConley on September 14, 2009 4:19:42 PM]

Share this post


Link to post
Share on other sites
Yeah I figured the bool was from other errors. I have tried that, but it seems to be something to do with the inclusion guards, because it is only allowing things to be "used" once, as soon as I it gets to another file that wants to include it, it doesn't actually do so, and then goes all undefined for that file. This being based on me switching around my #include "Junction.h" and #include "Road.h", with Road first I get 2 errors, basically saying TwoWayRoad there is no definition of "Road" since I want to inherit from road, but TwoWay Road is included in Junction.h

#ifndef TWOWAYROAD_H
#define TWOWAYROAD_H

#include "Road.h"
#include "Junction.h"
#include "Vehicle.h"

namespace TrafficClasses
{
class TwoWayRoad : public Road
{
};
}
#endif




#ifndef TRAFFICMANAGER_H
#define TRAFFICMANAGER_H

#include "Road.h"
#include "Junction.h"


class TrafficManager
{

};
#endif



before I had the includes in trafficmanager switched

I've been looking at this for an hour trying to figure out if I screwed up syntax or something, but I can't find anything and its really started to piss me off since it seems there isn't anything "wrong" with the code.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this