What I'm doing is writing my own version of the = operator. So when you way
temp = student[j]; the compiler will call my version of the = operator instead of the compiler's default version. The parameter to the operator is the equilivent of passing
student[j] by reference to any normal function.
I believe the reason your sort does not work as you wrote it is because the structure contains c++ STL class -- std::string. In such cases when the structure includes other class objects you should write the overloaded = operator.
That might also be similar to writing a swap function
void swap(if1& f1, if1& f2)
{
if1 temp;
temp.idnum = f1.idnum;
temp.lastname = f1.lastname;
temp.firstname = f1.firstname;
temp.examscore = f1.examscore;
temp.hwscore = f1.hwscore;
f1.idnum = f2.idnum;
// etc for f1
f2.idnum = temp.idnum;
// etc for f2
}
As you can see, the above code is pretty lengthly. The overloaded = operator is consideratly shorter and less pron to typing errors.
Last edited by Ancient Dragon : May 9th, 2008 at 7:56 pm.
'Politics' is made up of two words, 'poli,' which is Greek for 'many,' and 'tics,' which are blood-sucking insects.
- Gore Vidal
Being ignorant is not so much a shame as being unwilling to learn. - Benjamin Franklin