title: Convert implicitly float to other type
body: <p>For example, I have a class called <code>Length</code>.</p>
  
  <pre><code>class Length {
  public:
      static const float METER_TO_FLOAT_RATIO;
  
      Length();
      void setValue(float valueInMeter);
      operator const float();
  
  private:
      float valueInMeter_;
  };
  
  const float METER_TO_FLOAT_RATIO= 10;
  
  Length::Length() {}
  
  Length::operator const float() {
      return this-&gt;valueInMeter_ * METER_TO_FLOAT_RATIO;
  }
  
  void drawRectangle(Length width, Length height) {
      //draw width * height rectangle
  }
  
  int main() {
  
      Length width, height;
  
      width = 20.0f;
      height = 10.0f;
  
      drawRectangle(width, height);
  
      return 0;
  }
  </code></pre>
  
  <p>I asked <a href="https://stackoverflow.com/questions/31107327/is-it-possible-to-get-private-variable-value-using-class-instance-name">this question</a> to figure it out how to convert implicitly from <code>Length</code> to <code>float</code> but I forgot to or didn't ask about how to convert backward. The method which converts backward will call this statement:</p>
  
  <pre><code>    valueInMeter_ = valueInFloat_ / METER_TO_FLOAT_RATIO; //valueInFloat_ is the parameter
  </code></pre>