title: C++ overloaded functions and implicit casts
body: <p>I have some code that works correctly, but I want to make sure that it will always work correctly under the C++ standard.</p>
  
  <p>I've created two types which are implicitly converted to double, and created a sin() function for each of the types. I tested it and the correct sin() overload is called, but is it guaranteed that the compiler will not decide to cast the object instance implicitly to double and call the math.h functions?</p>
  
  <p>In addition, does it matter if my classes and sin() overloads are in a namespace? Will it matter if I template any of them?</p>
  
  <pre><code>struct AngleDegrees;
  struct AngleRadians;
  
  inline double degs2Rads(double degs) { return degs * PI / 180.0; }
  inline double rads2Degs(double degs) { return degs * 180.0 / PI; }
  
  struct AngleDegrees
  {
  private:
      double m_val;
  
  public:
      explicit AngleDegrees(double val) : m_val(val) { }
      explicit AngleDegrees(const AngleRadians&amp; rads);
  
      operator double() const { return m_val; }
  };
  
  struct AngleRadians
  {
  private:
      double m_val;
  
  public:
      explicit AngleRadians(double val) : m_val(val) { }
      explicit AngleRadians(const AngleDegrees&amp; degs);
  
      operator double() const { return m_val; }
  };
  
  inline AngleDegrees::AngleDegrees(const AngleRadians&amp; rads)
  {
      m_val = rads2Degs(rads);
  }
  
  inline AngleRadians::AngleRadians(const AngleDegrees&amp; degs)
  {
      m_val = degs2Rads(degs);
  }
  
  inline double sin(const AngleDegrees&amp; degs)
  {
      std::cout &lt;&lt; "called sin(AngleDegrees)\n";
      AngleRadians rads(degs);
      return sin((double)rads);
  }
  
  inline double sin(const AngleRadians&amp; rads)
  {
      std::cout &lt;&lt; "called sin(AngleRadians)\n";
      return sin((double)rads);
  }
  </code></pre>