473,396 Members | 1,975 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Bad initialization example in standard?

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?
Sep 1 '08 #1
1 1288
On Sep 1, 9:40*am, Old Wolf <oldw...@inspire.net.nzwrote:
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)
Sep 1 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

50
by: Charles Stapleton | last post by:
Given the folowing class class Ctest{ public: Ctest( int i, int j) :a(i) { b = j; } private: int a, b; } When creating an object of type Ctest, what advantage is there to setting
6
by: Alexander Stippler | last post by:
Hi, I wonder about the behaviour of como and icc on some very simple program. I thought initializing members of classes, which are of class type, would be 'direct initialized' (as the standard...
4
by: DaKoadMunky | last post by:
I was recently looking at some assembly code generated by my compiler. When examining the assembly code associated with constructors I noticed that the dynamic-dispatch mechanism was enabled...
3
by: DanielBradley | last post by:
Hello all, I have recently been porting code from Linux to cygwin and came across a problem with static const class members (discussed below). I am seeking to determine whether I am programming...
30
by: questions? | last post by:
say I have a structure which have an array inside. e.g. struct random_struct{ char name; int month; } if the array is not intialized by me, in a sense after I allocated a
23
by: Jess | last post by:
Hello, I understand the default-initialization happens if we don't initialize an object explicitly. I think for an object of a class type, the value is determined by the constructor, and for...
4
by: Jess | last post by:
Hello, I tried several books to find out the details of object initialization. Unfortunately, I'm still confused by two specific concepts, namely default-initialization and...
20
by: JohnQ | last post by:
The way I understand the startup of a C++ program is: A.) The stuff that happens before the entry point. B.) The stuff that happens between the entry point and the calling of main(). C.)...
11
by: subramanian100in | last post by:
Suppose we have a class named Test. Test obj; // assuming default ctor is available Test direct_init(obj); // direct initialization happens here Test copy_init = obj; // copy initialization...
5
by: kiryazev | last post by:
Hello. Given the code below does C++ Standard guarantee that the function my_init() will be called before main()? struct A { A() { my_init(); } };
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.