title: Ambiguous call of constructor from overloaded operator function in C++
body: <p>I'm trying to use an overloaded operator for a class with the following members and functions :</p>
  
  <pre><code>class MyVector {
  
    private:
      int           *data;
      unsigned int  vector_size;
  
    public:
      MyVector();
      MyVector(unsigned int n);
      MyVector(unsigned int size, int *in_array=NULL);
      MyVector(const MyVector&amp; copy);
      ~MyVector();
      void print();
  
      // Assignment operator.
      MyVector&amp; operator=(const MyVector&amp; v);
  
      friend MyVector operator*(const int &amp;lhs, MyVector &amp;rhs);
  
      friend MyVector operator*(MyVector &amp;rhs, int &amp;lhs);
  
      MyVector operator*(MyVector &amp;vector);
  };
  
  // Implementing operator overloading.
  MyVector operator*(int &amp;lhs, MyVector &amp;rhs);
  MyVector operator*(MyVector &amp;lhs, int &amp;rhs);
  </code></pre>
  
  <p>Inside one of my operator overloading functions, this is what I'm trying to do:</p>
  
  <pre><code>MyVector operator*(const int &amp;lhs, MyVector &amp;rhs) {
  
      unsigned int size = rhs.vector_size;
  
      // Create new vector.
      MyVector *v = new MyVector(static_cast&lt;unsigned int&gt;(size));
  
      for (unsigned int i = 0; i &lt; rhs.vector_size; i++) {
          v -&gt; data[i] = lhs * rhs.data[i];
      }
  
      return *v;
  }
  </code></pre>
  
  <p>I'm getting the following error :</p>
  
  <pre><code>MyVector_fxns.cpp: In function 'MyVector operator*(const int&amp;, MyVector&amp;)':
  MyVector_fxns.cpp:42:60: error: call of overloaded 'MyVector(unsigned int)' is ambiguous
    MyVector *v = new MyVector(static_cast&lt;unsigned int&gt;(size));
  </code></pre>
  
  <p>Before you mark this as a duplicate, I have checked <a href="https://stackoverflow.com/questions/4672152/call-of-overloaded-function-is-ambiguous">this link</a> and none of the solutions worked for me.</p>
  
  <p>Out of the three possible constructors, only 1 should be called here. What is causing the error despite me passing the correct type in the constructor argument ?</p>