(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:

  1. prevent that Thing is modified
  2. prevent that Thing cannot be read
  3. prevent that Thing is modified in some other way than #1
  4. document the internal assumptions of the function

 

View the answer of this exercise.

 

 

 

 

 

Feedback