Good evening Daniweb, I have another idiotic problem which comes from making an arrival subclass out of Event. I have a few other subclasses of Event and they aren't giving me any trouble. I have tried to copy/paste/rewrite to eliminate any stupid typos.

Arrival.h:7: error: expected class-name before ‘{’ token

#ifndef ARRIVAL_H
#define ARRIVAL_H

#include "Event.h" 

using namespace std;

class Train;
class Arrival : public Event{
public:
	Arrival(int time, Train* newTrain);
	void print();
	void activate();
	~Arrival(); 
};
#endif

I have a few other subclasses of Event and they aren't giving me any trouble.

How are their class declarations different from this one? I don't see anything in this one that's incorrect.

you need {} in class train;

so it needs to be

class Train{};

Also can you explain this bit here?

Arrival(int time, Train* newTrain);

you need {} in class train;

so it needs to be

class Train{};

No, that's a forward declaration. You don't need the braces. If you are going to use another class as an object in this class, that class must be defined first. However you don't need the full declaration you can "forward declare" it just so that the compiler knows it exists.

Also can you explain this bit here?

Arrival(int time, Train* newTrain);

This is a constructor for Arrival which takes two arguments, an integer and a pointer to an object of type Train (hence the forward declare before).

I don't know if this has anything to do with the problem at hand but when you define a constructor aside from the default one you have to explicitly define the default one. So you'd need: Arrival() {} amongst your public declarations (or you can implement something if you need a default behavior).

I would like to see Event.h

Can you please upload the same?

Also, posting in bits and pieces of code is most irritating.

You are posting it because you don't know what the error is. Then how do you expect yourself to understand what part of code is causing the problem. Just because the compiler is pointing to one line doesn't make that line the culprit.

I'm curious if it is the Event.h, why are some of the derived classes working and not others?

@OP: have you actually been able to employ the other derived classes in (working) code or was that just speculation?

I concur with Thomas, it couldn't at all hurt for us to have more of your code to test.

Arrival.h:7: error: expected class-name before ‘{’ token

#ifndef ARRIVAL_H
#define ARRIVAL_H

#include "Event.h"

using namespace std;

Most likely you are not including anything from the std namespace via the Event .h, so the namespace std remains unknown to the compiler and cannot be used there. I.e. perhaps remove the using namespace std; altogether, (if there will be no use for it in that header file). Otherwise, #include the necessary headers and you'll be able to keep the rest of this header file as is.

Event.h

#ifndef EVENT_H

#define EVENT_H
#include "NodeItem.h"
#include "Train.h"
using namespace std;

class Train;
class Event : public NodeItem {

	protected:
	int time;
	Train * train;

	public:
	virtual ~Event(); 
	int compareTo(NodeItem* item);
	virtual void print()=0;
	virtual void activate()=0;
	void setTime(int time); 
	int getTime();
	void setTrain(Train* train);
	Train* getTrain();

};
#endif

for reference Departure.h which isn't giving me trouble
Note: this one doesn't mind that it don't forward declare Train, I figure this means it's getting Event.h forward declare of it, or I was wrong in my previous statement saying they're not giving me trouble, I haven't tested them individualy yet.

#ifndef DEPARTURE_H

#define DEPARTURE_H
#include "Event.h"
using namespace std;

class Departure : public Event{
public:
	Departure(int time, Train * newTrain);
	void print();
	void activate();
	~Departure(); 
};
#endif

I'll test my code seperatly without Arrival to see what it says in a bit, thank you for the responses so far.

things to try:
Try without Arrival (to test others)
Try without Namespace Std
Make a NULL constructor

Note: this one doesn't mind that it don't forward declare Train, I figure this means it's getting Event.h forward declare of it, or I was wrong in my previous statement saying they're not giving me trouble, I haven't tested them individualy yet.

Arrival shouldn't need it then either then as it's part of Event.h. It's possible that's goofing you up too. Well, try all the suggestions and see what happens.

Alright I ended up completely rewriting Arrival.cpp and Arrival.h even though I couldn't distinguish what was wrong with them, and now I've managed to make it work and now face new errors (which I'll post in another thread when I exhaust my options)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.