This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Error on Member Initialization


Hi Lyle,

>Is there any _real_ difference between these two ways of initializing?

Yes.  The real difference is that the initializer list occurs whether or not
it is explicitly specified.  Putting the initialization code in the
constructor's body MAY incur a performance penalty.  That's a MAY, not a FOR
SURE ... the only way to know for certain is by profiling the optimized
release executable.

In some situations, it is necessary to put more complex resource acquisition
code in the constructor's body.

But, generally speaking, initialization lists are preferable over
initialization via the constructor's body.

The sample code you presented is amenable to the preferred initialization
list solution.

HTH,
--Eljay


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]