(C++) Exercise \#1: a foolproof function
August 7, 2019 · View on GitHub
(C++) Exercise #1: a foolproof function
Difficulty: 3/10
Date added: 10th of June 2008
In this exercise, you must write a foolproof function.
You are the maintainer of a Thing and the function ReadThing below.
struct Thing { int mX }; //Thing must be passed by normal (that is, non-smart) pointer void ReadThing(Thing * thing) { //Read Thing }
Make the function ReadThing foolproof. There are four different modifications to do:
- prevent that Thing is modified
- prevent that Thing cannot be read
- prevent that Thing is modified in some other way than #1
- document the internal assumptions of the function
View the answer of this exercise.
Feedback