Home > Back-end >  C write access conflict position
C write access conflict position

Time:03-12

When I want to create a dynamic array and write data, display position write access conflict is how to return a responsibility?
 
The class Score
{
Public:
Void inscore (string n, int m, int E, int P)
{
Num=n; Math=m; English=E; Programming=P;
Ascore=(m + E + P)/3;
}
Void showscore ()
{
Cout & lt; <"Student id:" & lt; }

Private:
String num.
Int Math;
Int English;
Int Programming;
Int ascore;
};
Int main ()
{
String Num.
Int math;
Int English;
Int programming;
Int I=0, length=3;
Score * p=new Score (length),
While (cin & gt;> Num & gt;> Math & gt;> English & gt;> Programming)
{
P [I] inscore (Num, math, English, programming).
i++;
If (I==length)
{
Int m;
Cout & lt; <"Whether or not to continue the input? Yes please enter 1, no please enter 0 "& lt; Cin & gt;> m;
If (m==1)
{
Score * tem=new Score (length + 3),
For (int k=0; K{
Tem (k)=p (k);
}
P=tem;
Length=length + 3;
The delete [] tem;
}
The else break;
}
}
For (int j=0; J & lt; length; J++)
{
P [j] showscore ();
}
The delete [] p;
return 0;
}


CodePudding user response:

 class Score 
{
Public:
Void inscore (string n, int m, int E, int P)
{
Num=n; Math=m; English=E; Programming=P;
Ascore=(m + E + P)/3;
}
Void showscore ()
{
Cout & lt; <"Student id:" & lt; }

Private:
String num.
Int Math;
Int English;
Int Programming;
Int ascore;
};
Int main ()
{
String Num.
Int math;
Int English;
Int programming;
Int I=0, length=3;
Score * p=new Score (length),
While (cin & gt;> Num & gt;> Math & gt;> English & gt;> Programming)
{
P [I] inscore (Num, math, English, programming).
i++;
If (I==length)
{
Int m;
Cout & lt; <"Whether or not to continue the input? Yes please enter 1, no please enter 0 "& lt; Cin & gt;> m;
If (m==1)
{
Score * tem=new Score (length + 3),
For (int k=0; K{
Tem (k)=p (k);
}
Length=length + 3;
The delete [] p;
P=tem;
}
The else break;
}
}
For (int j=0; J & lt; length; J++)
{
P [j] showscore ();
}
The delete [] p;
return 0;
}

CodePudding user response:

If lack of copy constructor

CodePudding user response:

45 ~ 47 line write wrong, should be recycling p points to the original memory, and then let the p point to the new allocation of three elements of memory
Line 45: delete [] p;
Line 46: p=tem;
Line 47: length=length + 3;

CodePudding user response:

You cross a line!!!!!!!!!!
  • Related