in reply to confusion about blessing inside a constructor
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.
|
|---|