[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c++

Bad initialization example in standard?

Old Wolf

9/1/2008 1:40:00 AM

In 12.6.1 of n2521, it says:

"When an aggregate (whether class or array) contains
members of class type and is initialized by a brace-
enclosed initializer list, each such member is
copy-initialized by the corresponding assignment-expression."

Then the example is given:
complex v[6] = { 1, complex(1,2), complex(), 2 };

where 'complex' is a small class defined in the 12.6
for exemplary purposes.

According to the above paragraph, v[1] should be
copy-constructed from the temporary complex(1,2).

However, the explanation of the example code says:
"complex::complex(double,double) is called for the
initialization of v[1]".

That is, it says that v[1] is directly constructed with
arguments 1,2, and no copy constructor is involved.

Is the example rationale wrong, or have I misinterpreted
the paragraph quoted above?
1 Answer

bood

9/1/2008 3:56:00 AM

0

On Sep 1, 9:40 am, Old Wolf <oldw...@inspire.net.nz> wrote:
> In 12.6.1 of n2521, it says:
>
>   "When an aggregate (whether class or array) contains
>   members of class type and is initialized by a brace-
>   enclosed initializer list, each such member is
>   copy-initialized by the corresponding assignment-expression."
>
> Then the example is given:
>   complex v[6] = { 1, complex(1,2), complex(), 2 };
>
> where 'complex' is a small class defined in the 12.6
> for exemplary purposes.
>
> According to the above paragraph, v[1] should be
> copy-constructed from the temporary complex(1,2).
>
> However, the explanation of the example code says:
>   "complex::complex(double,double) is called for the
>   initialization of v[1]".
>
> That is, it says that v[1] is directly constructed with
> arguments 1,2, and no copy constructor is involved.
>
> Is the example rationale wrong, or have I misinterpreted
> the paragraph quoted above?

I think it means that before the copy constructor is called, '1' has
to be converted to complex first, which is done by calling the
constructor complex::complex(double, double) (A.K.A. implicite
conversion)