C++ 2011 and beyond - delegation of construction jobs

In C++98, you may need to repeat code in constructors. now you can modularize beautifully.

 class X {
  int a;
 public:
  X(int x) { if (0<x && x<=max) a=x; else throw bad_X(x); }
  X() :X{42} { }
  X(string s) :X{lexical_cast<int>(s)} { }
  // ...
 };

Compiled from : http://www.stroustrup.com/C++11FAQ.html#delegating-ctor

.VeenusNotes

Comments