Bad initialization example in standard?

O

Old Wolf

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?
 
B

bood

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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top