The Controlled
Vars library is a set of templates that help you avoid bugs in your
C++ software by using safe guards for all the basic C++ types.
Quite often you create a class with a set of members. Write the first version of the contructor and everything works perfectly. Later, you come back to your class and decide that you need another variable member. You add that int and ... forget to initialize it in your constructor. The compiler doesn't tell you anything since this is perfectly legal C++ code. Some compiler may be capable of telling you that you read the integer before it is defined, but frankly, if you count on that, you will not find the problem very often.
Instead, you can use controlled variables. The library offers 3 methods:
Note that all of the side effects disappear once you remove the Controlled Vars debug flag. For example, the random number version becomes a very simple typedef of the corresponding type.
This document is part of the Snap! Websites Project.
Copyright by Made to Order Software Corp.