| krnacandrej (12) | |||
|
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/
| |||
|
|
|||
| Athar (4466) | |
|
What are you asking exactly? In any case, disregard that article - the code is horrible. Not sure why it hasn't been removed. | |
|
|
|
| krnacandrej (12) | |
|
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 ? | |
|
|
|
| Athar (4466) | |
|
The first is called an initializer list. The second overloads operator=. The keyword to search for is "operator overloading". | |
|
|
|
| andywestken (1966) | |||
|
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.
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
|
|||
| siavoshkc (21) | |
|
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/ | |
|
|
|