1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
#include <iostream>

class X {
   private:
      const char* name;
   public:
      X(const char* name) : name(name) {
	 std::cout << "X \"" << name << "\" constructed" << std::endl;
      }
      ~X() {
	 std::cout << "X \"" << name << "\" destructed" << std::endl;
      }
};

int main() {
   for (int i = 0; i < 2; ++i) {
      X x1 = "x1 within for loop";
      {
	 X x2 = "x1 in the inner block";
	 X x3 = "x2 in the inner block";
      }
      X x4 = "x4 at the end of the for loop";
   }
}