Hi. I'm trying to overload read data from a file and re-order a queue based on the data. This is the code I have so far:
Main()
priority_queue <Event> queue;
while (inFile2 >> INPUT) {
if (INPUT == "INPUT") {
inFile2 >> wrname >> time >> value;
Event *event = new Event(wrname, time, value);
queue.push(*event);
}
The Event Class Header:
#ifndef EVENT_H
#define EVENT_H
#include <string>
class Event
{
public:
Event();
Event(std::string, int, char);
bool operator<(const Event &)const;
int getTime();
~Event();
void execute();
private:
int time = 0;
char val;
static int tiebreaker;
};
The Event Class Implementation:
Event::Event(std::string n1, int t1, char v1)
{
tiebreaker++;
time = t1;
val = v1;
}
bool Event::operator<(const Event & ev)const
{
if (time > ev.time) {
return true;
}
else if (time < ev.time) {
return false;
}
else {
if (tiebreaker > ev.tiebreaker) {
return true;
}
else {
return false;
}
}
}
The compilation error is returning the error: '<': no operator found which takes a left-hand operand of type 'const Event' (or there is no acceptable conversion). When I change the function to const, it shows an error: "unresolved external symbol "private: static int Event::tiebreaker" (?tiebreaker@Event@@0HA)"