Home > Back-end >  Novice for help, the problem appeared on the destructor, when I put the destructor function annotati
Novice for help, the problem appeared on the destructor, when I put the destructor function annotati

Time:04-20

#include
using namespace std;
The class Integer
{
Protected:
//vector dimension
Int n;
};
Class Vector: public Integer
{
//input vector
Friend istream& Operator> (istream& , Vector&);
//output vector
Friend ostream& Operator<(ostream& , Vector&);
Public:
//incoming vector dimensions constructor
The Vector (int=1);
//copy constructor
The Vector (const Vector&);
~ the Vector ();
//vector addition
The Vector operator + (Vector&);
//vector inner product
Double operator * (Vector&);
//vector assignment
Vector& Operator=(const Vector&);
//vector sentenced to
Boolean operator==(const Vector&);
//vector modulus
Double operator () ();
Protected:
Int * v.
};
Vector: : Vector (int Length)
{
If (Length & lt;=0 | | Length> 100)
{
Cout & lt; <"Temporarily does not support the dimension and high dimension vector operations... \ n ";
Abort ();
}
The else
{
Int Factor=0;
V=new int (Length),
N=Length;
For (; Factor & lt; n; Factor Factor + 1)={v [Factor]=0; }
}
}
Vector: : Vector (const Vector& The vector)
{
V=vector. V;
N=vector. N.
}
//the destructor has problems
Vector: : ~ Vector ()
{
The delete [] v.
V=NULL;
N=0;
}
//vector addition
The Vector Vector: : operator + (Vector& The vector)
{
If (n==vector. N)
{
Int Factor=0; The Vector Temp (n);
For (; Factor & lt; n; Factor Factor + 1)={Temp. V (Factor)=v (Factor) + vector, v (Factor); }
Return Temp.
}
The else
{
Cout & lt; <"Temporarily does not support vector operations of different dimensions... \ n ";
Abort ();
}
}
//vector inner product
Double Vector: : operator * (Vector& The vector)
{
If (n==vector. N)
{
Int Factor=0; Int Result=0;
For (; Factor & lt; n; Factor Factor + 1)={Result=Result + v (Factor) * vector v (Factor); }
Return the Result.
}
The else
{
Cout & lt; <"Temporarily does not support vector operations of different dimensions... \ n ";
Abort ();
}
}
//vector assignment
Vector& Vector: : operator=(const Vector& The vector)
{
If (n==vector. N)
{
Int Factor=0;
For (; Factor & lt; n; Factor Factor + 1)={v [Factor]=vector. V (Factor); }
return *this;
}
The else
{
Cout & lt; Abort ();
}
}
//vector sentenced to
Bool Vector: : operator==(const Vector& The vector)
{
If (n==vector. N)
{
Int Factor=0;
For (; Factor & lt; n; Factor=Factor + 1)
{
If (v (Factor)==vector. V [Factor]) {continue; }
The else {return false. }
}
return true;
}
The else {return false. }
}
//vector modulus
Double Vector: : operator () ()
{
Int Factor=0; Double Model=0;
For (; Factor & lt; n; Factor Factor + 1)={Model=double (v (Factor)) * double (v/Factor); }
The Model=SQRT (Model);
Return the Model;
}
//input and output vector
Istream& Operator> (istream& Input, Vector& The vector)
{
Int Factor=0, Length=0;
Cout & lt; <"According to the vector dimension of input data, please... ";
Length=vector. N;
For (; Factor & lt; Length; Factor Factor + 1)={cin & gt;> The vector. V (Factor); }
Return the Input;
}
Ostream& Operator<(ostream& The Output, Vector& The vector)
{
Int Factor=0, Length=0;
Length=vector. N;
Cout & lt; <"(";
For (; Factor & lt; Length; Factor=Factor + 1)
{
Cout & lt; If (Factor==Length - 1) {cout & lt; <"\ b"; }
}
Cout & lt; <");
Return the Output;
}
Int main ()
{
//this is the main function of test
The Vector Vector_0 (2), Vector_1 (2), Vector_2 (2);
Cin & gt;> Vector_0 & gt;> Vector_1 & gt;> Vector_2;
Vector_0=Vector_1 + Vector_2;
Cout & lt; <"Vector is:" & lt; }

CodePudding user response:

Main function accidentally wrong there, run the "Vector_0 deleted" , neglect, I'm sorry.,,,
  • Related