class StudentEntry {...} *entryList[MAX_STUDENT];

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){}
	void operator = (StudentEntry *entry)
	{
		name = entry->name;
		mark = entry->mark;
	}
	NAME name;
	MARK mark;
}*entryList[MAX_STUDENT];
What are you asking exactly?
In any case, disregard that article - the code is horrible.
Not sure why it hasn't been removed.
Why ":" is behind (NAME name, MARK mark) at line "StudentEntry(NAME name, MARK mark): name(name), mark(mark){}"
Is it special constructor?

And "void operator = (StudentEntry *entry) { ... }" is for what ?
The first is called an initializer list.
The second overloads operator=. The keyword to search for is "operator overloading".
Yes, that tutorial is poorly written.

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).
Last edited on
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.

To learn C++ you should find a C++ tutorial like: http://www.cplusplus.com/doc/tutorial/
Topic archived. No new replies allowed.