Samudra said:
I have a class which defines multiple overloaded constructors. Within the
class methods is there a elegant way to determine which constructor was used
to instantiate the class (without setting flags in the constructor)?
In general, no. The behaviour of a class should be influenced by it's
functions, it's properties, and arguments passed to it's constructors
or functions. Not as a side effect of how the object was constructed.
If you need it's behaviour to be different, then make that explicit by
exposing an argument to the constructor, to ask for this different
behaviour.
About the only way your request might make sense is if there are a
mixture of private and public constructors, and you need different
behaviour if one of you're private constructors has been called. About
the only thing to do in this case would be to set a flag (which you've
stated a preference away from).
The simple reason for this? The vast majority of people do not want or
need to know which constructor was used. If this information was to be
automatically available, it would incur additional overhead for
everyone using the framework who does not need this information. It's
the same reason, for instance, that you cannot easily find out when an
object was constructed - unless you explicitly store that information
yourself within the constructor.
Damien