Chapter 47. Control Flow
Difficulty: 6
How well do you really know the order in which C++ code is executed? Test your knowledge against this problem.
“The devil is in the details.” Point out as many problems as possible in the following (somewhat contrived) code, focusing on those related to control flow.
#include <cassert> #include <iostream> #include <typeinfo> #include <string> using namespace std; // The following lines come from other header files. // char* itoa( int value, char* workArea, int radix ); extern int fileIdCounter; // Helpers to automate class invariant checking. // template<class T> inline void AAssert( T& p ) { static int localFileId = ++fileIdCounter; if( !p.Invariant() ) { cerr << "Invariant failed: file " << localFileId << ...
Get Exceptional C++: 47 Engineering Puzzles, Programming Problems, and Solutions now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.