On Fri, 09 Apr 2004 15:49:55 +0200, Alexander Stippler
<> wrote:
>>>class Ref
>>>{
>>> public:
>>> Ref() : vec_(Vec()) { }
>>
>> If you had omitted the base initializer totally, or used it but omitted
>> the "Vec()" from inside the parens, it would have called the default
>> constructor.
>> -leor
First of all, sorry, I said "base initializer" when of course it is a
"member" initializer. No idea why my brain did that (not enough coffee yet,
I guess....)
>
>Consider Vec() replaced by e.g Vec(a,b,c). Why is it necessary to (1) create
>Vec(a,b,c) and then (2) copy it into vec_ using the copy constructor?
Okay, several issues here. First, are you aware that you do not need, in
/either/ case, to use the "temporary" syntax? IOW, you can either omit the
member initializer completely (which invokes vec_'s default constructor)
or, to pass the ctor args, use:
Ref() : vec_(a,b,c) {}
This results in the best performance imaginable. The fact that some
compilers take your version and optimize away the temporaries, but others
don't, is a QOI issue...and I wouldn't even say the ones that do not suffer
from lower QOI, but rather than their implementors chose to focus on other
features (perhaps "export" in the case of EDG, the authors of the Comeau
front-end) that were likely to make more of a difference to more folks.
>Shouldn't it just directly initialize the vec_ object?
>By the way, gcc does exactly this, como and icc not. This situation is IMO
>comparable to copy constructors given a temporary class object, e.g.
>
>Vec v(Vec());
>
>would result in the direct initialization of v with the temporary Vec(), not
>first create it and then copy it into v. Where is the difference?
QOI.
-leor
--
Leor Zolman --- BD Software ---
www.bdsoft.com
On-Site Training in C/C++, Java, Perl and Unix
C++ users: Download BD Software's free STL Error Message Decryptor at:
www.bdsoft.com/tools/stlfilt.html