fork download
  1. #include <iostream>
  2. #include <queue>
  3. #include <vector>
  4.  
  5. using std::priority_queue;
  6. using std::cout;
  7. using std::vector;
  8.  
  9. class Base {
  10. public:
  11. virtual bool operator() (int l, int r) const {
  12. cout << "Should not be called" << std::endl;
  13. return 0;
  14. }
  15. virtual ~Base() {}
  16. };
  17. class A : public Base {
  18. public:
  19. bool operator() (int l, int r) const override {
  20. cout << "Should be called!!!!";
  21. return l < r;
  22. }
  23. };
  24. int main() {
  25. priority_queue<int, vector<int>, Base> pq((A()));
  26. pq.push(1);
  27. pq.push(2);
  28. pq.push(3);
  29. pq.push(0);
  30. cout << pq.top();
  31. return 0;
  32. }
Success #stdin #stdout 0s 3416KB
stdin
Standard input is empty
stdout
Should not be called
Should not be called
Should not be called
1