title: Print Class-type Properties ( cout << class.property )
body: <p>I'm learning C++, and I have a question about print class type property.</p>
  
  <p>I'm trying to get <code>Point(x, y)</code>'s position, and print it.</p>
  
  <p>Getting position is perfectly work as I thought, but printing does not.</p>
  
  <p>I think it should work, but it doesn't, maybe I am missing something.</p>
  
  <p>Should I cast it to any other value type which could print out?</p>
  
  <p>so I just tried <code>cout &lt;&lt; "The position is: " &lt;&lt; p1.getPosition();</code> and I got an error:</p>
  
  <pre><code>prog.cc:29:7: error: no match for 'operator&lt;&lt;' (operand types are 'std::ostream' {aka 'std::basic_ostream'} and 'Point')
     29 |  cout &lt;&lt; p1.getPosition();
        |  ~~~~ ^~ ~~~~~~~~~~~~~~~~
        |  |                     |
        |  |                     Point
        |  std::ostream {aka std::basic_ostream}
  </code></pre>
  
  <p>Here's my code.</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  class Point{
      double x;
      double y;
  public:
      Point getPosition();
      void setPosition(double x_, double y_);
      Point operator+(const Point&amp; p);
      Point(double x_, double y_)
      {
          x = x_;
          y = y_;
      }
  };
  
  Point Point::getPosition(){ return Point(x, y); }
  void Point::setPosition(double x, double y){    x = this-&gt;x;    y = this-&gt;y;    }
  Point Point::operator+(const Point&amp; p)
  {
      return Point((x+p.x), (y+p.y));
  }
  
  
  int main(void)
  {
      Point p1(5.0, 5.0);
      cout &lt;&lt; "The position is: " &lt;&lt; p1.getPosition() &lt;&lt; endl;       //error occured
      return 0;   
  }
  </code></pre>
  
  <p>Thanks you for your help :)</p>