| 1) I will reply to your answer by posting a few pages of the improved tutorial on operator overloading. Better read these instead of the original. You will receive many answers.
2) You implemented the most important part: operator[].
However, I announced a caveat. Here it is:
What happens if you pass const objects to operator=() ?
How do you fix it?
On the next replies I will post the relevant pages. The moral of the story so far was:
For any class that holds members that dynamically allocate memory, implement these three items:
1) copy constructor
2) overloaded assignment operator
3) a destructor
This is called: The Rule Of Three.
- copy ctor
prevents double deletion errors.
- assignment operator
prevents double deletion errors and self destruction and memory leaks.
- destructor
cleanup obviously
The second moral is this:
When implementing operator[], consider implenting another version to deal with const objects. Try this one alone. After that, I will post my complete CArray class because you've worked hard enough.
You're answers were basically incomplete and inaccurate. However, the impression I've got is that you did real good. Good attempts. If this was an intermadiate test, I would have given you a score of 80% out of 100%. For the effort.
__________________ |