I get this output:
CTor 42
DTor 0
Return A
Postblit 42
DTor 84
DTor 42
with the following code. I'm a bit confused about the Postblit. I
return by ref so I thought that I get a const ref of the original
A.
[code]
import std.stdio;
struct A {
public:
int id;
Forget to say: I use dmd 2.062.
I've filled a bug report.
On 05/23/13 11:47, Namespace wrote:
I get this output:
CTor 42
DTor 0
Return A
Postblit 42
DTor 84
DTor 42
with the following code. I'm a bit confused about the Postblit. I return by
ref so I thought that I get a const ref of the original A.
ref
That was what I also expected. But opAssign is not called.
On Thu, 23 May 2013 13:29:49 +0200, Namespace rswhi...@googlemail.com
wrote:
That was what I also expected. But opAssign is not called.
Because you have a postblit. It's called instead of opAssign.
--
Simen
On Thursday, 23 May 2013 at 11:31:19 UTC, Simen Kjaeraas wrote:
On Thu, 23 May 2013 13:29:49 +0200, Namespace
rswhi...@googlemail.com wrote:
That was what I also expected. But opAssign is not called.
Because you have a postblit. It's called instead of opAssign.
[code]
import std.stdio;
To be more detailed:
I'd expected that the code with 'getA' without ref
[code]
A getA() {
writeln(Return A);
return this._a;
}
[/code]
would print this output:
CTor 42
opAssign R 42
DTor 42
Return A
Postblit 42
opAssign R 84
DTor 84
DTor 42
On 05/23/13 13:34, Namespace wrote:
A a = b.getA();
Postblit, no opAssign call.
You're constructing, not assigning. Try reassigning 'a' to see
opAssign in action. It's a bit unintuitive and easy to miss -
which I did too, hence my misleading first reply - sorry.
The issue is that D has
I know that D has (sadly) no C++ references, but I still think
that
A a = some_existing_A;
should call opAssign.
And if I do this:
A a;
a = b.getA();
I get what I want. What a spasm...
On Thursday, 23 May 2013 at 11:57:04 UTC, Namespace wrote:
I know that D has (sadly) no C++ references, but I still think
that
A a = some_existing_A;
should call opAssign.
Now I see what has you confused. Whether postblit or opAssign is
called, depend on left, not right side of assignment.
On Thursday, 23 May 2013 at 11:57:04 UTC, Namespace wrote:
I know that D has (sadly) no C++ references, but I still think
that
A a = some_existing_A;
should call opAssign.
Actually, it is similar to C++ : http://codepad.org/lkPMU1Ne
On Thursday, 23 May 2013 at 12:07:40 UTC, Maxim Fomin wrote:
On Thursday, 23 May 2013 at 11:57:04 UTC, Namespace wrote:
I know that D has (sadly) no C++ references, but I still think
that
A a = some_existing_A;
should call opAssign.
Now I see what has you confused. Whether postblit or
On 05/23/13 13:57, Namespace wrote:
I know that D has (sadly) no C++ references, but I still think that
A a = some_existing_A;
should call opAssign.
Not opAssign, but user-defined copy-constructor. But D does not have
them either...
artur
On Thursday, 23 May 2013 at 12:29:04 UTC, Artur Skawina wrote:
On 05/23/13 13:57, Namespace wrote:
I know that D has (sadly) no C++ references, but I still think
that
A a = some_existing_A;
should call opAssign.
Not opAssign, but user-defined copy-constructor. But D does not
have
them
On 05/23/13 14:30, Namespace wrote:
On Thursday, 23 May 2013 at 12:29:04 UTC, Artur Skawina wrote:
On 05/23/13 13:57, Namespace wrote:
I know that D has (sadly) no C++ references, but I still think that
A a = some_existing_A;
should call opAssign.
Not opAssign, but user-defined
17 matches
Mail list logo