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 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) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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
|
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...
|
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...
|
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...
|
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
|
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...
|
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...
|
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.)...
|
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...
|
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();
}
};
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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...
|
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,...
|
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...
|
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,...
|
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...
|
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...
|
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...
| |