pass a function into a priority queue

M

Michael

#include<queue>
using namespace std;
bool comp(int,int);
priority_queue<int>q(comp);

test.cpp:4: error: no matching function for call to
‘std::priority_queue<int, std::vector<int, std::allocator<int> >,
std::less<int> >::priority_queue(bool (&)(int, int))’
/usr/include/c++/4.3/bits/stl_queue.h:403: note: candidates are:
std::priority_queue<_Tp, _Sequence, _Compare>::priority_queue(const
_Compare&, const _Sequence&) [with _Tp = int, _Sequence = std::vector<int,
std::allocator<int> >, _Compare = std::less<int>]
/usr/include/c++/4.3/bits/stl_queue.h:374: note:
std::priority_queue<int, std::vector<int, std::allocator<int> >,
std::less<int> >::priority_queue(const std::priority_queue<int,
std::vector<int, std::allocator<int> >, std::less<int> >&)

How can I make comp as the comparison function for q?
 
A

Alf P. Steinbach

* Michael:
#include<queue>
using namespace std;
bool comp(int,int);
priority_queue<int>q(comp);

test.cpp:4: error: no matching function for call to
‘std::priority_queue<int, std::vector<int, std::allocator<int> >,
std::less<int> >::priority_queue(bool (&)(int, int))’
/usr/include/c++/4.3/bits/stl_queue.h:403: note: candidates are:
std::priority_queue<_Tp, _Sequence, _Compare>::priority_queue(const
_Compare&, const _Sequence&) [with _Tp = int, _Sequence = std::vector<int,
std::allocator<int> >, _Compare = std::less<int>]
/usr/include/c++/4.3/bits/stl_queue.h:374: note:
std::priority_queue<int, std::vector<int, std::allocator<int> >,
std::less<int> >::priority_queue(const std::priority_queue<int,
std::vector<int, std::allocator<int> >, std::less<int> >&)

How can I make comp as the comparison function for q?

Reading the documentation will help.

Reading the error message above may also help (just read one little bit at a
time, going forward slowly enough that it makes sense) -- what does it say?

If you don't have documentation of the standard library, try downloading the
latest draft of the C++0x standard, and/or visit e.g. Microsoft's MSDN Library
pages and/or Dinkumware's library docs and/or StlLib pages or whatever.


Cheers & hth.,

- Alf
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top