When I call the following section of code, I get to the section to enter an integer for enter number of grades to drop and my program crashes.
void Course::enterGCInfo(int num)
{
GradeCat tempGC;
string tempStr = "";
cout << "Enter Grade Category Name: ";
cin >> tempStr;
tempGC.setGCName(tempStr);
double tempDbl = 0.0;
cout << "Enter Grade Percentage: ";
cin >> tempDbl;
tempGC.setGCPerc(tempDbl);
int tempInt = 0;
cout << "Enter Number of Grades To Drop: ";
cin >> tempInt;
tempGC.setNumToDrop(tempInt);
setGradeCat(num,tempGC);
refresh();
}
This is the error message:
Unhandled exception at 0x004149eb in Grade Tracker.exe: 0xC0000005: Access violation reading location 0x3343f1c8.
I'm using Visual Studio 2010 Express - Start Debugging. When it reaches this error it takes me to following code in file xstring
bool _Grow(size_type _Newsize,
bool _Trim = false)
{ // ensure buffer is big enough, trim to size if _Trim is true
if (max_size() < _Newsize)
_Xlen(); // result too long
if (this->_Myres < _Newsize)
_Copy(_Newsize, this->_Mysize); // reallocate to grow
else if (_Trim && _Newsize < this->_BUF_SIZE)
_Tidy(true, // copy and deallocate if trimming to small string
_Newsize < this->_Mysize ? _Newsize : this->_Mysize);
else if (_Newsize == 0)
_Eos(0); // new size is zero, just null terminate
return (0 < _Newsize); // return true only if more work to do
}
The cursor stops next to this line:
if (this->_Myres < _Newsize)
The function calls dealing with that Integer input
setNumToDrop
void GradeCat::setNumToDrop(int num)
{
numToDrop = num;
}
setGradeCat
void Course::setGradeCat(int num,GradeCat tempGC)
{
GCs[num] = tempGC;
}
GCs is an array of GradeCat objects
refresh
void Course::refresh()
{
calcGrade();
calcTotalPerc();
sortGradeCats();
}