I tries the below code, but I'm getting infinite loop that is infinite number of values in the output may I know the reason and what my mistake is: I'm getting the values to enter but after entering I'm getting infinite number of zeroes may the problem be solved: the below one is the code:
#include<iostream>
class Vector
{
int n,*a,i;
public:
Vector()
{
int n;
int *a;
}
Vector(int n)
{
a=new int[n];
std::cout<<"Enter array elements "<<std::endl;
for(i=0;i<n;i++)
{
std::cin>>a[i];
}
std::cout<<"the elements od the vector are: "<<std::endl;
for(i=0;i<n;i++)
{
std::cout<<a[i]<<std::endl;
}
}
Vector(Vector &v)
{
a=v.a;
std::cout<<"using Copy Constructor elements are:"<<std::endl;
for(i=0;i<n;i++)
{
std::cout<<a[i]<<std::endl;
}
}
Vector& operator=(const Vector& v)
{
int n=v.n;
a=v.a;
std::cout<<"after assigning values are:"<<std::endl;
for(i=0;i<n;i++)
{
std::cout<<a[i]<<std::endl;
}
delete []a;
return *this;
}
~Vector()
{
std::cout<<"Destructor called"<<std::endl;
}
};
int main()
{
Vector v1(4);
Vector v2(v1);
Vector v3;
v3=v1;
}