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 ?
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 ?
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).
This should work just fine. Just the syntax should be:
std::vector<std::priority_queue<A> >
(note the space (" ") near the end.