title: Is it dangerous to overload bool operator in this case
body: <p>I have seen comments or answers on SoF stating that overloading the cast operator to bool is dangerous and I should prefer the <code>void* operator</code> instead. Still I would like to ask if it is dangerous practice to use this operator in my use case and if yes why.</p>
  
  <p>I implement a simply geometry library and one of its most basic classes is a point that I define in the following way:</p>
  
  <pre><code>struct point {
    double x, y;
    bool real;
    point(double x_, double y_): x(x_), y(y_), real(true) {}
    point(): x(0), y(0), real(true) {}
  
    operator bool() {
      return real;
    }
  };
  </code></pre>
  
  <p>I will try to explain why I need the cast operator to bool. I have another class called line and I have a function declared as follows:</p>
  
  <pre><code>point intersect(const line&amp; a, const line&amp; b);
  </code></pre>
  
  <p>Now having overloaded the cast operator to bool of a point I can write both: <code>point p = intersect(a,b);</code> and <code>if (intersect(a,b))</code> thus either getting the intersection point of two lines or checking if two lines intersect. I use this in other places as well but I believe this example is enough to show the usage of the cast operator. Is my usage of the cast operator dangerous and if it is could you please give an example when the effect will not be as expected?</p>
  
  <p>EDIT: one small addition thanks to juanchopanza : in this project I am limited to not using c++11, so I can not make the operator explicit. </p>