Hi,
I am beginner and i haven't seen class like this...can any body explain me role of this class?
Whole code is from this site: http://www.cplusplus.com/articles/S8hv0pDG/
1 2 3 4 5 6 7 8 9 10 11 12
class StudentEntry
{
public:
StudentEntry(NAME name, MARK mark): name(name), mark(mark){}
voidoperator = (StudentEntry *entry)
{
name = entry->name;
mark = entry->mark;
}
NAME name;
MARK mark;
}*entryList[MAX_STUDENT];
And void operator = (StudentEntry *entry) is WRONG!!!
While it's legal C++ syntax, it's wrong semantically; operator= must always be defined using a (const) reference and return a ref to the instance.
1 2 3 4 5 6 7
StrudentEntry& operator=(const StudentEntry& entry)
{
name = entry.name;
mark = entry.mark;
return *this;
}
Note: Assuming name is a string and mark is an integer/double, and because this is a basic example, I have not protected against self assignment (as it's safe as it is).
Despite the errors in code I see many formatting problems that makes the text hard to read. I am not sure but I think the last revisions were not reviewed by moderators. I revised it again by the way.
@krnacandrej: The tutorial is about steps for building a program. The code in this tutorial at the implementation phase is not a well written C++ code and by many is considered even wrong.