fork(2) download
  1. #include <iostream>
  2. #include <queue>
  3. #include <cmath>
  4.  
  5. class C {
  6. protected:
  7. double a, b;
  8. public:
  9. C() {}
  10. C(double a, double b) { this->a = a; this->b = b; }
  11. friend std::ostream &operator<<(std::ostream &s, C &c) {
  12. s << '(' << c.a << ',' << c.b << ')';
  13. return s;
  14. }
  15. };
  16.  
  17. class CCompare : C {
  18. public:
  19. bool operator()(C &r, C &s) { return sqrt(r.a * r.a + r.b * r.b) < sqrt(s.a * s.a + s.b * s.b); }
  20. };
  21.  
  22. int main() {
  23. C c;
  24. std::priority_queue<C, std::vector<C>, CCompare> pq;
  25. pq.push(C(3, 1));
  26. pq.push(C(4, 1));
  27. pq.push(C(5, 9));
  28. pq.push(C(2, 6));
  29. pq.push(C(5, 3));
  30. while (!pq.empty()) {
  31. c = pq.top();
  32. pq.pop();
  33. std::cout << c << std::endl;
  34. }
  35. return 0;
  36. }
  37.  
  38.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In member function 'bool CCompare::operator()(C&, C&)':
prog.cpp:7: error: 'double C::a' is protected
prog.cpp:19: error: within this context
prog.cpp:7: error: 'double C::a' is protected
prog.cpp:19: error: within this context
prog.cpp:7: error: 'double C::b' is protected
prog.cpp:19: error: within this context
prog.cpp:7: error: 'double C::b' is protected
prog.cpp:19: error: within this context
prog.cpp:7: error: 'double C::a' is protected
prog.cpp:19: error: within this context
prog.cpp:7: error: 'double C::a' is protected
prog.cpp:19: error: within this context
prog.cpp:7: error: 'double C::b' is protected
prog.cpp:19: error: within this context
prog.cpp:7: error: 'double C::b' is protected
prog.cpp:19: error: within this context
stdout
Standard output is empty