Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(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

 

Feedback can be posted at post the Programmer's Heaven page about this article.

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict