a text on optimizing C++

Lubos Lunak kde-optimize@mail.kde.org
Fri, 24 Jan 2003 14:24:51 +0100


On Friday 24 of January 2003 14:18, David Leimbach wrote:
> >  It looks almost the same, but the latter may also sometimes produce
> > shorter code. Upon entering the constructor body, all constructors of
> > attributes have already been executed. So in this example, in the latter
> > case attr2 is directly initialized using a copy constructor, while in the
> > sooner case it's initialized using the default constructor, and then
> > operator= is used.
>
> So your claim is that with the initializer list the following has a shorter
> execution path?
>
> SomeClass obj = someOtherObj;
>
> I don't think operator = is involved at all in the above line of code
> regardless of whether the constructor uses initializer lists or not.  The
> above is *not* an assignment so why would it use the assignment operator?
> The above is an initialization that just happens to use the '=' token.

 Yes, you're right, in this case above, '=' is just syntactic sugar for 
calling the constructor. But this is something different, this is not 
initialization of data members in the constructor.

>
> At least I think that's correct... I know this comes up on newsgroups from
> time to time [comp.lang.c++.moderated] so I will google there. :)

-- 
Lubos Lunak
KDE developer
---------------------------------------------------------------------
SuSE CR, s.r.o.  e-mail: l.lunak@suse.cz , l.lunak@kde.org
Drahobejlova 27  tel: +420 2 9654 2373
190 00 Praha 9   fax: +420 2 9654 2374
Czech Republic   http://www.suse.cz/