I have a custom comparator for a priority queue.

using P = pair<int,int>;
class Compare
    bool operator() (P left, P right)
        return (left.second == right.second)? (m_recency[left.first] < m_recency[right.first]) :left.second > right.second;

m_recency is declared in another class which actually has the priority queue as a member like

std::unordered_map<int,int> m_recency;
std::priority_queue<P,std::vector<P>,Compare> q;

But it says m_recency was not declared in scope. How do i modify the comparator to allow use of map?

New contributor
codeforce is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

closed as off-topic by Quuxplusone, user673679, 200_success, vnp, Snowhawk Feb 11 at 1:43

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Quuxplusone, user673679, 200_success, vnp, Snowhawk
If this question can be reworded to fit the rules in the help center, please edit the question.

  • \$\begingroup\$ This SE site is intended for working code. Thus, I believe your question would be a better fit for Stack Overflow. \$\endgroup\$ – Juho Feb 10 at 20:59
  • 1
    \$\begingroup\$ This question is off-topic for CodeReview because we review working code; we don't tell you how to make broken code work. (But: look up "lambda functions" in C++11 and imagine how to apply that technique in your case. What information does your Compare class need to do its job, and how can you get that information into it?) \$\endgroup\$ – Quuxplusone Feb 10 at 21:00

Browse other questions tagged or ask your own question.