JiiPee <
n...@notvalid.com> wrote in news:829Bx.467861$ix5.1...@fx17.am4:
> On 19/08/2015 23:16, Ben Bacarisse wrote:
>> JiiPee <
n...@notvalid.com> writes:
>>> struct Coordinate
>>> {
>>> int x; // row
>>> int y; // column
>>> };
>>>
>>> Coordinate c;
>>> c = {2,7};
>> You assignment is, in fact, a call to a
>> compiler-defined assignment operator
>>
>> Coordinate &Coordiante::operator=(const Coordinate &other);
>>
>> and the {2, 7} is being used to initialize the single parameter. The
>> supplied opertaor simple does a member-wise assignment using = for
each
>> of the data members.
>
> ok but to be able to use the operator= the compiler must create a
> temporary object (like "other") out of {2, 7} , isnt it?
Yes, at least conceptually a temporary is created which is then copied to
c by using the copy assignment operator. If anything like the copy
assignment is identifiable in the compiled machine code is another
question, aggregates are pretty transparent to the compiler and can be
optimized heavily (even though copy assignment cannot be elided so easily
as copy constructor, AFAIK).