# include & lt; Iostream>
# include & lt; string.h>
using namespace std;
Class Vector {
int n;
Int * arr;
Public:
The Vector (int num=0) : n (num)
{
Arr=new int [n].
for(int i=0; i
{
Arr [I]=0;
}
}
The Vector (const Vector & amp; Vec) : n (Vec) n)
{
Arr=new int [n].
Memcpy (arr, Vec. Arr, n * sizeof (int));
}
~ the Vector () {delete [] arr; }
Friend ostream & amp; Operator<(ostream & amp; OS, const Vector & amp; Vec);
Friend cost & amp; Operator> (cost & amp; Is that the Vector & amp; Vec);
};
Ostream & amp; Operator<(ostream & amp; OS, const Vector & amp; Vec)
{
Int I;
for(i=0; i
{
Os
Os<" ";
}
Os
Return the OS;
}
Cost & amp; Operator> (cost & amp; Is that the Vector & amp; Vec)
{
for(int i=0; i
{
Is> Vec. Arr [I];
}
The return is;
}
Int main ()
{
int num;
Cin> Num.
The Vector vec1 (num);
cout
Cin> Vec1;
cout
Const Vector vec2=vec1;
cout
The Vector vec3 (num);
Vec3=vec2;
cout
return 0;
}
There is something wrong with
?What is memory transfinite... ...
CodePudding user response:
The Vector (int num=0) : n (num)
{
Arr=new int [n].//n==0, meaningless
for(int i=0; i{
Arr [I]=0;
}
}
The Vector (const Vector & amp; Vec) : n (Vec) n)
{
Arr=new int [n].//n==0, meaningless
Memcpy (arr, Vec. Arr, n * sizeof (int));
}
CodePudding user response:
You did not provide operator=, so wrong
CodePudding user response: