in reply to confusion about blessing inside a constructor

First, you should understand bless. It makes a variable into an object, which just means that you can call the methods of whatever class you blessed it into via the object itself.

In example #2, the class that the object is being blessed into is whatever one the constructor physically appears in. That's the default. It's better to have the constructor get the class from the argument list and bless into it explicitly (like example #3), so that some derived class can call the same constructor and still get an object of the derived class.

Example #1 is too clever for its own good, and is frequently frowned upon as cargo-cult programming (see 408726). It takes the class or an object as an argument, then (if an object) gets the class type before doing the bless.


Caution: Contents may have been coded under pressure.
  • Comment on Re: confusion about blessing inside a constructor