Why am I getting segmentation fault:11 in this piece of code? Is there a shortage of memory on my Mac? Or is there some other reason? I have MacBook Air RAM 8GB.
template<class T>
class vecto
{
T *v;
int size;
public:
vecto(int m)
{
size=m;
v=new T[m];
for(int i=0; i<size; i++)
v[i]=0;
cout<<"inside constructor 1."<<endl;
}
vecto(T *a)
{
for(int i=0; i<size; i++)
v[i]=a[i];
cout<<"inside constructor 2."<<endl;
}
};
int main()
{
int a1[3] = {1,2,3};
float a2[3] = {4,5,6};
vecto<int> v1(3); //constructor 1 called
vecto<float> v2(3); //constructor 1 called
v1=a1; //constructor 2 called
v2=a2; //constructor 2 called
return 0;
}