优先级队列重载错误:"二进制'<':找不到带有左侧操作数类型的运算符。"

时间:2017-12-11 05:45:15

标签: c++ visual-studio operator-overloading priority-queue

您好。我试图从文件中重载读取数据并根据数据重新排序队列。这是我到目前为止的代码:

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);

    }

事件类标题:

#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; 

};

事件类实现:

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;
        }

    }
}

编译错误返回错误:&#39;&lt;&#39;:找不到运算符,该运算符采用类型&#39; const事件&#39;的左手操作数。 (或者没有可接受的转换)。当我将函数更改为const时,它会显示错误:&#34;未解析的外部符号&#34; private:static int Event :: tiebreaker&#34; (?决胜局@ @@事件0HA)&#34;

0 个答案:

没有答案