going to go ahead and say this is homework. I'm trying to compile a program that uses virtual functions, and templates. However I'm getting the error:
Error: Expected template-name before '<' token struct compareItem : binary_function{
error: expected '{' before '<' token error: expected unqualified-id before '<' token
This is the main.C
#include "Item.h"
int main(){
priority_queue<Item*, vector<Item*>, compareItem> pq;
W* w = new W(0, &pq);
T* t = new T(10, &pq);
pq.push(w);
pq.push(t);
while(!pq.empty()){
Item* i = pq.top();
pq.pop();
i->Run();
}
return 0;
}
this is the Item.h
#ifndef ITEM_H
#define ITEM_H
#include <functional>
#include <queue>
#include <vector>
#include <iostream>
class Item{
int key;
public:
Item(int k) : key (k){}
friend class compareItem;
int getKey() {return key;}
void setkey(int x) {key = x;}
virtual void Run(){}
virtual ~Item(){}
};
struct compareItem : binary_function<Item*, Item*, bool>{
bool operator()(const Item* t1, const Item* t2) const{
return (t1->key > t2->key);
}
};
class W : public Item{
priority_queue<Item*, vector<Item*>, compareItem>* q;
public:
W(int k, priority_queue<Item*, vector<Item*>, compareItem >* q1) : Item (k), q(q1){}
void Run() {cout << "W at " << getKey() << endl;
setKey(getKey()+10);
q->push(this);
~W(){}
};
class T : public Item{
priority_queue<Item*, vector<Item*>, compareItem >* 1;
public:
T(int k, priority_queue<Item*, vector<Item*>, compareItem >* q1) : Item (k), q(q1){}
void Run() {cout << "T at " << getKey() << endl;
setKey(getKey()+25);
q->push(this);
~T(){}
};
#endif