Jump to content
  • Advertisement
Sign in to follow this  
JonConley

Inclusion Problems

This topic is 3377 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Try reading the article again. It lists the common problems with dealing with dependencies across multiple files in C++, yours included. And the solutions of course. [smile]

Hint: #include isn't the only way...

Share this post


Link to post
Share on other sites
Thanks a bunch, I don't know why I didn't think to just forward declare, I've done it before, but I guess I just got into a rush to get the structure finished.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!