Note – You may also want to check other answers, especially the one with decltype and lambda
You should declare a class Compare
and overload operator()
for it like this:
class Foo { }; class Compare { public: bool operator() (Foo, Foo) { return true; } }; int main() { std::priority_queue<Foo, std::vector<Foo>, Compare> pq; return 0; }
Or, if you for some reasons can’t make it as class, you could use std::function
for it:
class Foo { }; bool Compare(Foo, Foo) { return true; } int main() { std::priority_queue<Foo, std::vector<Foo>, std::function<bool(Foo, Foo)>> pq(Compare); return 0; }
Related Posts:
- Why do we need virtual functions in C++?
- Why is “using namespace std;” considered bad practice?
- How do I fix a “Expected Primary-expression before ‘)’ token” error?
- How to find out if an item is present in a std::vector?
- What are the rules of the std::cin object in C++?
- C++ code file extension? What is the difference between .cc and .cpp
- How do I reverse a C++ vector?
- Is there a maxheap in the C++ standard library?
- C++ Error: ISO C++ Forbids Comparison Between Pointer and Integer [-fpermissive]
- Replace part of a string with another string
- Time complexity of a Priority Queue in C++
- segmentation fault 11 in C++ on Mac
- How to append text to a text file in C++?
- In C++, what is wx.h?
- Issue with std::stol – ‘std::invalid_argument’ what(): stol
- Is there a tab equivalent of std::endl within the standard library?
- Why am I getting string does not name a type Error?
- Using “super” in C++
- new types may not be defined in a return type – C++
- printf with std::string?
- Append an int to a std::string
- cc1plus: error: unrecognized command line option “-std=c++11” with g++
- C++ undefined reference to WinMain@16 (Code::Blocks)
- bit vectors in c++
- Very basic inheritance: error: expected class-name before ‘{’ token
- mkdir c++ function
- Error: “expected primary-expression before int”
- error C2065: ‘cout’ : undeclared identifier
- Operator Overloading C++; too many parameters for << operation
- How do I check if a Key is pressed on C++
- I’m getting the error “stoi is not a member of std” in myprogramminglab [duplicate]
- Initializing an array of objects
- Passing an array by reference
- When should you use a class vs a struct in C++?
- What is archive mode in rsync?
- What does int argc, char *argv[] mean?
- Meaning of = delete after function declaration
- Using NULL in C++?
- Turn off pager for psql’s interactive output
- What are C++ functors and their uses?
- invalid conversion from ‘const char*’ to ‘char*’
- How to update multiple columns in single update statement in DB2
- Check if a string is palindrome
- what does the __file__ variable mean/do?
- What is an ‘undeclared identifier’ error and how do I fix it?
- Is C++ an Object Oriented language?
- Initializing a two dimensional std::vector
- Returning multiple values from a C++ function
- Eclipse C++ : “Program “g++” not found in PATH”
- Center Plot title in ggplot2
- no default constructor exists for class
- Press Enter to Continue
- How to trim a std::string?
- git add . -> still “nothing to commit” with new files
- C++: std does not have member “string”
- git submodule add error: does not have a commit checked out
- Fatal error: ‘stdafx.h’ file not found
- “The certificate chain was issued by an authority that is not trusted” when connecting DB in VM Role from Azure website
- How do I add the MinGW bin directory to my system path?
- How do I get monitor resolution in Python?
- SQL array flattening: Why doesn’t CROSS JOIN UNNEST join every nested value with every row?
- QltAW.png
- std::wstring VS std::string
- Function to calculate R2 (R-squared) in R
- SonarQube Runner vs Scanner
- Is dependency injection useful in C++
- Missing files, DirectX SDK (d3dx9.lib, d3dx9.h)
- gcc: undefined reference to
- how to center form using bootstrap 4
- Valgrind: invalid read of size 4 -> sigsegv, works fine without valgrind and in visual studio
- “Field has incomplete type” error
- How to implement OnFragmentInteractionListener
- C++ Returning reference to local variable
- Multidimensional Vectors in C++
- How do I flush the cin buffer?
- C++ Return value, reference, const reference
- Making a countdown timer in C++
- Error haskell: not in scope. What does that mean?
- OpenMP set_num_threads() is not working
- What is a null-terminated string?
- Right Justifying output stream in C++
- Serial Port (RS -232) Connection in C++
- Fixing Segmentation faults in C++
- how to destroy an object in C++
- Use of ‘const’ for function parameters
- What is the difference between the dot (.) operator and -> in C++?
- Different ways to deallocate an array – c++
- Android marshmallow : Galaxy Note 4 Screen Overlay Detected
- How to determine the version of the C++ standard used by the compiler?
- Declare a bit in C++
- Difference between the int * i and int** i
- wp_localize_script with mce_external_plugins in wordpress
- How do I display the latest Flickr OAuth embedded image on the frontpage?
- Posts2Posts plugin and wp user frontend connect programmatically
- Limiting the posts on the homepage to one taxonomy? [closed]
- Need a method for base_url() or home_url() in CF7 additional settings [closed]
- Pulling Individual Posts from WP_Query
- How to check, if user commented before, on comment_post action?
- add_image_size sizes not stored
- parsererror | SyntaxError: Unexpected token < in JSON at position 0