fork download
  1. #include <iostream>
  2.  
  3. struct point
  4. {
  5. point(int a, int b) : x(a), y(b) {}
  6.  
  7. int horiz() const { return x; }
  8. int vert() const { return y; }
  9.  
  10. private:
  11. int x,y;
  12. };
  13.  
  14. std::ostream& operator << (std::ostream & out, point const& pt)
  15. {
  16. return out << pt.horiz() << ", " << pt.vert();
  17. }
  18.  
  19. int main()
  20. {
  21. point p{0,2};
  22.  
  23. std::cout << p << "\n";
  24.  
  25. p = {42,420};
  26.  
  27. std::cout << p << "\n";
  28. }
Success #stdin #stdout 0s 2852KB
stdin
Standard input is empty
stdout
0, 2
42, 420