This code gives the segmantation fault Is the constructor called when assigning array to template specifically in this program? Please explain in detail if the constructor is called why is segmantation fault? if not called isn't this the syntax error
#include <iostream>
using namespace std;
const int size=3;
template<class T>
class vector{
T *v;
public:
vector(){
v = new T[size];
for(int i=0;i<size;i++)
{
v[i]=0;
}
}
vector(T *a){
for (int i=0;i<size;i++)
{
v[i]=a[i];
}
}
T operator*(vector &v){
T sum=0;
for (int i=0;i<size;i++)
{
sum+=this->v[i]*v.v[i];
}
return sum;
}
void display(){
for (int i=0;i<size;i++)
{
cout << v[i] <<"\t";
}
}
};
int main()
{
int x[3]={1,3,5};
int y[3]={2,4,6};
vector<int> v1;
vector<int> v2;
v1=x;
v2=y;
v1.display();
cout<<endl;
v2.display();
return 0;
}