class vector
{
int *v;
int size;
vector ( int m )
{
v=new int[size=m];
for(int i=0;i<size;i++)
v[i]=0;
}
vector( int *a)
{
for(int i=0;i<size;i++)
v[i]=a[i];
}
};
int main()
{
int x[3]={1,2,3};
vector v1(3);
vector v2(3);
v1=x;
v2=y;
return 0;
}
My doubt is , how can the constructor being called twice?
Is that even allowed? I thought constructors are invoked when objects are created.Also why is the argument of 2nd constructor int *a
instead of int a[]
. Is there any difference between those two?