I'm trying to write a simple function that returns time to wait for a car that arrives at the gate of a parking lot. I'm using a priority_queue for this purpose and my code doesn't seem to compile.
Here's the function
std::time_t waitingTime(std::vector<car* > v){
//std::unordered_map<std::time_t, std::string> lookup;
std::vector<std::time_t> timeVector;
std::priority_queue<std::time_t, timeVector, std::greater<std::time_t>> Q;
for(auto it = v.begin(); it != v.end(); it++){
car* c = *it;
timeVector.push_back(c->exit);
//lookup[c->exit] = c->id;
}
for(std::time_t t :timeVector){
Q.push(t);
}
const std::time_t t = Q.top();
Q.pop();
return t;
};
Here's my driver code
std::time_t now = time(0);
car* c1 = new car("A", now+2, now+4);
car* c2 = new car("A", now, now+3);
car* c3 = new car("A", now, now+1);
std::vector<car* > v;
v.push_back(c1);
v.push_back(c2);
v.push_back(c3);
std::time_t t = waitingTime(v);
std::cout<<t<<std::endl;
Here's the compilation error.
38: error: template argument for template type parameter must be a type
std::priority_queue<std::time_t, timeVector, std::greater<std::time_t>> Q;