cyrux
cyrux

Reputation: 243

C++ Vector/list of priority queues?

Why wouldn't C++ allow something like that ?

I need to have multiple priority queues, the number of which would be determined at run time.

This fails to compile

std::vector<std::priorityqueue<Class A>>.

Is there a better approach ?

Upvotes: 2

Views: 6222

Answers (2)

jpalecek
jpalecek

Reputation: 47762

This should work just fine. Just the syntax should be:

std::vector<std::priority_queue<A> >

(note the space (" ") near the end.

Upvotes: 1

James McNellis
James McNellis

Reputation: 355009

The correct code would be:

std::vector<std::priority_queue<A> >

Note that Class does not belong next to A, priority_queue has an underscore in it, and there is a space required between the two right angle brackets (>> is parsed as a right shift operator).

This also requires that A is less-than comparable (if it is not, then you must provide a comparison function to be used by the priority queue).

Upvotes: 6

Related Questions