title: c++ - Is there a way to auto-cast values when assigning them to references`?
body: <p>I'm wondering if there is some way that C++ autocasts values that I want to assign to a reference.</p>
  
  <pre><code>class X{
  public:
      X(int x){
      }
  };
  
  int main(){
      X x = 5;        //works
      X&amp; y = 6;       //doesn't work
      X&amp; z = (X)7;    //works
      return 0;
  }
  </code></pre>
  
  <p>As you can see, assigning 6 to the reference y does not work without casting it before. Is there something I can add in the definition of the class X to make this work without the casting, so that the non-working line would work?</p>
  
  <p>Basically I want to achieve that, for example a function like this:</p>
  
  <pre><code>void doSomething(X&amp; x){
      //...
  }
  </code></pre>
  
  <p>Could be called like this after that:</p>
  
  <pre><code>doSomething(7);
  </code></pre>
  
  <p>Is it possible?</p>