"Walter Bright" <[email protected]> wrote in message news:[email protected]... > dsimcha wrote: >> I've never understood the recommendation not to put complex logic in >> the >> constructor. > > Complex logic is fine, just logic that cannot fail. > >> If you need complex logic to establish the class's invariant, or >> need to initialize complicated immutable data structures, where else >> is that logic >> supposed to go? > > For example, allocating resources that might fail, can be done with a > separate initialization function: > > auto c = new Class; > c.create();
Commonly called "2 step construction". But you forgot to add the check on the return val from c.create().
