Problem: Compile, link is OK, run at the end of debug error errors, Damage:after Normal block (#187) at 0x00033160
Source:
Child function problem, independent of main function, Have[pn][rn],need[i][j],offer[rn of main function is passed, return an integer value
int Issafe (Vector < vector<int> >& have, vector < vector<int> >& need, Vector <int>& Amp Offer
{
int safe=0;
Vector < vector<int> >have1 (PN);//global variable: PN,RN
Vector < vector<int> >need1 (PN);
Vector <int> Offer1 (RN);
for (int i=0; i<pn; i++)
{
for (int j=0; j<rn; j + +)
{
HAVE1[I][J]=HAVE[I][J]; Have1[i].push_back (Have[i][j]);
Need1[i][j]=need[i][j];//need1[i].push_back (Need[i][j]);
}
}
return safe;
}
Cause: The main reason for this is the incorrect use of dynamically allocated memory. The have1 vector only knows the one-dimensional vector that contains the PN, but does not know how many elements each of the one-dimensional vectors are, so have1[i][j]=have[i][j]; is wrong; this accesses the wrong memory---the content of that address is unknown.
There is debug error, VC detected this error message. --
Resolution: Green part changed to red part
Reference http://www.programfan.com/club/showpost.asp?id=146259&t=o: