-1

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;
Thomas G
  • 113
  • 1
  • 3
  • 6
  • Do you know what a template parameter is? If yes, reread the error message. if not: http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list – Baum mit Augen Sep 29 '15 at 23:41

1 Answers1

0

You need to provide types as arguments for template, not objects. Declaration of your queue should look like following:

std::priority_queue<std::time_t> queue;

Note, I didn't specify other template arguments - default was exactly what i needed.

SergeyA
  • 61,605
  • 5
  • 78
  • 137