> Programming Languages > C++
Various Topics Home | Disclaimer | Report Adult Posts

Various Topics on C++



C++ - "Create new objects in a constructor" in Programming Languages


Old 06-20-2004   #1
..i..
 
Default Create new objects in a constructor

Is it a good idea to construct some other objects using "new" within a
constructor of a cl*** in two cases, exception disabled and enabled? Thanks
in advance!


 
Old 06-20-2004   #2
..ct.. ..zar..
 
Default Re: Create new objects in a constructor

"ctick" <ctick@flare.com> wrote...
> Is it a good idea to construct some other objects using "new" within a
> constructor of a cl*** in two cases, exception disabled and enabled?


If exceptions are disabled, you probably use '(nothrow)' version
of 'new' and then you get NULL when cannot allocate, and have to
put your constructed object in some kind of "incomplete" state,
which should be queriable. If exceptions are enabled (as in any
normal situation, I am not sure why one would disable them, well,
maybe to compile code for ROM or something), then the object
creation (invocation of the constructor) has to be 'tried' and
exceptions need to be caught. But that should be pretty usual by
now.

You should probably decide for yourself whether programming that
'incompletely constructed' state in your object is a good idea; it
is a decent work-around (around the absence of exceptions) IMO.

V


 

Thread Tools
Display Modes





Powered by vBulletin®
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0