title: No constructor could take the source type, or constructor overload resolution was ambiguous??(template)
body: <p>I am making generic vector class with template</p>
  
  <p>I almost finished them</p>
  
  <p>but this <strong>vector.push_back(element);</strong> line let constructor tell me it is ambiguous.</p>
  
  <p>edit:ok, so I put the whole code</p>
  
  <p>the problem was below:</p>
  
  <p>(222): note: No constructor could take the source type, or constructor overload resolution was ambiguous(its push_back function which I put (222) in front of that line)</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;stdlib.h&gt;
  
  using namespace std;
  template &lt;typename T&gt;
  class BasicVector
  {
  private:
      int vector_size;
      int vector_capacity;
      T* data;
  
      void resize();
  
  public:
      BasicVector() {};
      BasicVector(int);
      ~BasicVector();
  
      T&amp; at(int);
      T&amp; operator[](int);
      T&amp; front();
      T&amp; back();
  
      void push_back(T);
      void insert(int, T);
      void pop_back();
  
      int size();
      int capacity();
  
      void print();
  };
  
  
  template &lt;typename T&gt;
  void BasicVector&lt;T&gt;::resize()
  {
      T* temp = data;
      T* newDataCap = new T[vector_capacity * 2];
      this-&gt;data = newDataCap;
      for (int i = 0; i &lt; vector_size; i++)
      {
          data[i] = temp[i];
      }
      vector_capacity *= 2;
      delete[] temp;
  }
  
  template &lt;typename T&gt;
  BasicVector&lt;T&gt;::BasicVector(int capacity)
  {
      if (capacity &lt; 16)
      {
          capacity = 16;
      }
      else if (capacity &gt;= 16 &amp;&amp; capacity % 2 == 1)
      {
          capacity = capacity + 1;
      }
      vector_capacity = capacity;
      data = new T[vector_capacity];
      vector_size = 0;
  }
  
  template &lt;typename T&gt;
  BasicVector&lt;T&gt;::~BasicVector()
  {
      for (int i = 0; i &lt; vector_size; i++)
      {
          data[i] = 0;
      }
      delete[] data;
  }
  
  template &lt;typename T&gt;
  T&amp; BasicVector&lt;T&gt;::at(int elemNumber)
  {
      if (elemNumber &gt; vector_size)
      {
          exit(1);
      }
      else
      {
          return data[elemNumber];
      }
  }
  
  template &lt;typename T&gt;
  T&amp; BasicVector&lt;T&gt;::operator[](int elemNumber)
  {
      if (elemNumber &gt; vector_size)
      {
          exit(1);
      }
      else
      {
          return data[elemNumber];
      }
  }
  
  template &lt;typename T&gt;
  T&amp; BasicVector&lt;T&gt;::front()
  {
      return data[0];
  }
  
  template &lt;typename T&gt;
  T&amp; BasicVector&lt;T&gt;::back()
  {
      return data[vector_size];
  }
  
  template &lt;typename T&gt;
  void BasicVector&lt;T&gt;::push_back(T element)
  {
      if (vector_size == vector_capacity)
      {
          resize();
      }
      data[vector_size] = element;
      vector_size++;
  }
  
  template &lt;typename T&gt;
  void BasicVector&lt;T&gt;::insert(int  elemNum, T element)
  {
      if (vector_size == vector_capacity)
      {
          resize();
      }
      int* temp = new int[vector_size];
  
      for (int i = 0; i &lt; vector_size; i++)
      {
          temp[i] = data[elemNum + i - 1];
      }
  
      for (int j = 0; j &lt; vector_size; j++)
      {
          data[elemNum + j] = temp[j];
      }
  
      data[elemNum - 1] = element;
  
      vector_size++;
  
      delete[] temp;
  }
  
  template &lt;typename T&gt;
  void BasicVector&lt;T&gt;::pop_back()
  {
      data[vector_size] = 0;
      vector_size--;
  }
  
  template &lt;typename T&gt;
  int BasicVector&lt;T&gt;::size()
  {
      return vector_size;
  }
  
  template &lt;typename T&gt;
  int BasicVector&lt;T&gt;::capacity()
  {
      return vector_capacity;
  }
  
  template &lt;typename T&gt;
  void BasicVector&lt;T&gt;::print()
  {
      cout &lt;&lt; "elements(" &lt;&lt; vector_size &lt;&lt; "):";
      for (int i = 0; i &lt; vector_size; i++)
      {
          cout &lt;&lt; " " &lt;&lt; data[i];
      }
      cout &lt;&lt; endl;
  }
  
  template &lt;typename T&gt;
  void theCoolFunction(BasicVector&lt;T&gt; &amp;vector)
  {
      cout &lt;&lt; "Now accepting commands (quit to exit program): "&lt;&lt; endl;
  
      string choice;
      while (choice != "quit")
      {
          cin &gt;&gt; choice;
  
          if (choice == "get")
          {
              int elemNum;
              cin &gt;&gt; elemNum;
              cout &lt;&lt; vector[elemNum] &lt;&lt; endl;
          }
          else if (choice == "at")
          {
              int elemNum;
              cin &gt;&gt; elemNum;
              cout &lt;&lt; vector.at(elemNum) &lt;&lt; endl;
          }
          else if (choice == "front")
          {
              cout &lt;&lt; "The first element of the vector is: " &lt;&lt; vector.front() &lt;&lt; endl;
          }
          else if (choice == "back")
          {
              cout &lt;&lt; "The last element of the vector is: " &lt;&lt; vector.back() &lt;&lt; endl;
          }
          else if (choice == "insert")
          {
              int  elemNum, element;
              cin &gt;&gt; elemNum &gt;&gt; element;
              vector.insert(elemNum, element);
          }
          else if (choice == "push")
          {
              int element;
              cin &gt;&gt; element;
         (222)vector.push_back(element);
          }
          else if (choice == "pop")
          {
              vector.pop_back();
          }
          else if (choice == "size")
          {
              cout &lt;&lt; vector.size() &lt;&lt; endl;
          }
          else if (choice == "capacity")
          {
              cout &lt;&lt; vector.capacity() &lt;&lt; endl;
          }
          else if (choice == "print")
          {
              vector.print();
          }
          else if (choice == "quit")
          {
              cout &lt;&lt; "Exiting Program." &lt;&lt; endl;
              exit(0);
          }
          else
          {
              cout &lt;&lt; "invalid input" &lt;&lt; endl;
          }
      }
  }
  
  int main()
  {
      int dataType;
      cout &lt;&lt; "Specify what data type to store in vector:" &lt;&lt; endl;
      cout &lt;&lt; "1) int" &lt;&lt; endl;
      cout &lt;&lt; "2) float" &lt;&lt; endl;
      cout &lt;&lt; "3) dou! ble" &lt;&lt; endl;
      cout &lt;&lt; "4) string" &lt;&lt; endl;
      cout &lt;&lt; "5) bool" &lt;&lt; endl;
      cin &gt;&gt; dataType;
  
      int capacity;
      cout &lt;&lt; "Enter starting capacity of vector: ";
      cin &gt;&gt; capacity;
      cout &lt;&lt; endl;
  
  
      if (dataType == 1)
      {
          BasicVector&lt;int&gt;vector(capacity);
          theCoolFunction&lt;int&gt;(vector);
      }
      else if (dataType == 2)
      {
          BasicVector&lt;float&gt;vector(capacity);
          theCoolFunction&lt;float&gt;(vector);
      }
      else if (dataType == 3)
      {
          BasicVector&lt;double&gt;vector(capacity);
          theCoolFunction&lt;double&gt;(vector);
      }
      else if (dataType == 4)
      {
          BasicVector&lt;string&gt;vector(capacity);
          theCoolFunction&lt;string&gt;(vector);
      }
      else if (dataType == 5)
      {
          BasicVector&lt;bool&gt;vector(capacity);
          theCoolFunction&lt;bool&gt;(vector);
      }
  
      return 0;
  }
  </code></pre>