Simple user defined vector template example
<p>Consider the following code:</p>

<pre><code>template&lt;typename T&gt;
class vecTor
{
int size;
T *v;
   public:
vecTor(int s=0): size(s), 
  v(new T[size]) // conv. ctor [1]
    {
       for(int i=0; i&lt;size; i++)
           v[i]=0;
    }

 vecTor(T *x,int s) // [2] this conv. ctor produces seg. fault if called
{
    size=s;
    for(int i=0; i&lt;size; i++)
    v[i] = x[i];
}

void vecTorset(T *a,int s)  // this method works fine
{                           // instead of [2]
    size=s;
    for(int i=0; i&lt;size; i++)
        v[i] = a[i];
}

~vecTor()
{
    delete [] v;
}

void printvec() const;
};

  template&lt;typename T&gt;
   void vecTor&lt;T&gt;::printvec() const
    {
     cout&lt;&lt;"Vector is:\n";
      for(int i=0; i&lt;size; i++)
      cout&lt;&lt; v[i] &lt;&lt;" ";
      cout&lt;&lt;"\n";
    }

int main()
{
  int a[3]= {3,5,7};

  vecTor&lt;int&gt; v1(3);

  v1=vecTor&lt;int&gt;(a,3);   // this call produces seg. fault

  //v1.vecTorset(a,3);    //this call works fine

  v1.printvec();

  return 0;
</code></pre>

<p>}</p>

<p>If I call second conversion ctor</p>

<pre><code>      v1=vecTor&lt;int&gt;(a,3);
</code></pre>

<p>I get a segmentation fault at codepad.org; it crashes on mingw. What could be the problem?</p>
