title: prefer conversion operator over conversion constructor
body: <p>I have the following code snippet:</p>
  
  <pre><code>class A
  {
  public:
    A() : x_(0), y_(0) {}
  
    A(int x, int y) : x_(x), y_(y) {}
  
    template&lt;class T&gt;
    A(const T &amp;rhs) : x_(rhs.x_), y_(rhs.y_)
    {
    }
  
    int x_, y_;
  };
  
  class B
  {
  public:
    B() {}
  
    operator A() const { return A(c[0],c[1]); }
    int c[2];
  };
  
  void f()
  {
    B b;
    (A)b; // &lt;&lt; here the error appears, compiler tries to use 
          //         template&lt;class T&gt; A(const T &amp;rhs)
  }
  </code></pre>
  
  <p>Why compiler uses <code>A</code>'s constructor? How can I make it use <code>B</code>'s conversion operator to <code>A</code>?</p>
  
  <p>I use MSVS2010 compiler. It gives me these errors:</p>
  
  <pre><code>main.cpp(9): error C2039: 'x_' : is not a member of 'B'
            main.cpp(17) : see declaration of 'B'
            main.cpp(28) : see reference to function template instantiation 'A::A&lt;B&gt;(const T &amp;)' being compiled
            with
            [
                T=B
            ]
  main.cpp(9): error C2039: 'y_' : is not a member of 'B'
            main.cpp(17) : see declaration of 'B'
  </code></pre>
  
  <p><strong>UPD</strong>:
  All right, implicit convert as Nawaz said really works. Let's make it more complicated, how make the following code work?</p>
  
  <pre><code>void f()
  {
    std::vector&lt;B&gt; b_vector(4);
    std::vector&lt;A&gt; a_vector( b_vector.begin(), b_vector.end() );
  }
  </code></pre>
  
  <p><strong>UPD</strong>: <code>A</code> is the class in 3rd party lib which code I can't edit, so I can't remove <code>A</code>'s converting constructor.</p>
  
  <p><strong>UPD</strong>: the simplest solution I've found for the moment is to define specialization of converting constructor for <code>B</code>. It can be done outside of 3rd party lib:</p>
  
  <pre><code>template&lt;&gt; A::A( const B &amp;rhs ) : x_(rhs.c[0]), y_(rhs.c[1]) {}
  </code></pre>