I'm not a professional programmer, so please don't hesitate to state the obvious.
My goal is to use a std::multiset
container (typedef EventMultiSet
) called currentEvents
to organize a list of structs, of type Event
, and to have members of class Host
occasionally add new Event
structs to currentEvents
. The structs are supposed to be sorted by one of their members, time. I am not sure how much of what I am trying to do is legal; the g++ compiler reports (in "Host.h") "error: 'EventMultiSet' has not been declared." Here's what I'm doing:
// Event.h
struct Event {
public:
bool operator < ( const Event & rhs ) const {
return ( time < rhs.time );
}
double time;
int eventID;
int hostID;
};
// Host.h
...
void calcLifeHist( double, EventMultiSet * ); // produces compiler error
...
void addEvent( double, int, int, EventMultiSet * ); // produces compiler error
// Host.cpp
#include "Event.h"
...
// main.cpp
#include "Event.h"
...
typedef std::multiset< Event, std::less< Event > > EventMultiSet;
EventMultiSet currentEvents;
EventMultiSet * cePtr = ¤tEvents;
...
Major questions
Thank you very much in advance.
The compiler errors are simply because your typedef is in the wrong place - only main.cpp knows about it. It looks like you probably want it in Event.h, which both of the others include.
I'm not sure exactly what you're asking - but possibly you want to pass by reference not by pointer?
I don't see anything wrong with it - though you might want to provide the other comparisons (>
, <=
, ...) too.