code snippet from Core C++ part 4 Stephan T. Lavavej