Struct beeing moved around
Sean Kelly
sean at invisibleduck.org
Fri May 20 10:42:26 PDT 2011
On May 20, 2011, at 8:43 AM, so wrote:
> On Fri, 20 May 2011 17:30:33 +0300, Sean Kelly <sean at invisibleduck.org> wrote:
>
>> In main above you're declaring a new struct variable t which is default-constructed, then a temporary is created and initialized to 5, and then the temporary is copied onto t. It does seem like a postblit should probably occur in this scenario though.
>
> I am confused.
> There shouldn't be any copying, it is construction.
If you do the following:
MyStruct s;
A new instance of MyStruct is be created and default-initialized. Changing this to:
MyStruct s = MyStruct(5);
Is really just shorthand for:
MyStruct s;
s = MyStruct(5);
The compiler can translate this into a single construction (it does in C++), but I don't know that it's required to.
More information about the Digitalmars-d
mailing list