This is just part of my code.
For some unknown reason, the value of staff is correct after using copy constructor, however, once it goes out of the loop, 2 of s value's turn into -858993460, other values stay fine, look at the red lines part of the code
Staff s;
int currentLineNum;
for(int nLineNum = 1;;nLineNum++)
{
// read a buffer
char buffer[256];
pFileStream2->getline(buffer, 256);
if (pFileStream2->fail())
{
delete pFileStream2;
break;
}
// parse the individual fields
char userName[80];
char password[80];
int accessLevel;
int staffNumber;
char name[80];
char ICNumber[80];
char gender;
char designation[80];
char department[80];
char dateJoined[80];
char nationality[80];
char religion[80];
char dob[80];
char maritalStatus[80];
bool result = parseString( buffer,
userName,
password,
accessLevel,
staffNumber,
name, 80,
ICNumber,
gender,
designation,
department,
dateJoined,
nationality,
religion,
dob,
maritalStatus);
if (result == false)
{
cerr << "Error parsing string\n" << endl;
}
if(idArray[selection] == staffNumber)
{
currentLineNum = nLineNum;
Staff tempStaff ( userName,
password,
staffNumber,
name,
ICNumber,
gender,
designation,
department,
dateJoined,
nationality,
religion,
dob,
maritalStatus);
Staff s(tempStaff);
cout << " s number = " << s.staffNumber << "\n" //the value is correct
<< " s access level = " << s.accessLevel << endl;
// output the fields we parsed out
cout << " User Name = " << userName << "\n"
<< " Password = " << password << "\n"
<< " Staff Number = " << staffNumber << "\n"
<< " Name = " << name << "\n"
<< " IC Number = " << ICNumber << "\n"
<< " Gender = " << gender << "\n"
<< " Designation = " << designation << "\n"
<< " Department = " << department << "\n"
<< " Date Joined = " << dateJoined << "\n"
<< " Nationality = " << nationality << "\n"
<< " Religion = " << religion << "\n"
<< " Date of Birth = " << dob << "\n"
<< " Marital Status = " << maritalStatus << endl;
}
}
cout << " s number = " << s.staffNumber << "\n" //the values turns into -858993460
<< " s access level = " << s.accessLevel << endl;