Chaining struct method invocations
Namespace via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Sep 7 07:28:04 PDT 2015
On Monday, 7 September 2015 at 14:12:25 UTC, Bahman Movaqar wrote:
> I need some help understand the behaviour of my code[1].
> Specifically I have trouble with `add` method on line 79.
>
> My impression is that since it returns `this`, multiple
> invocations can be chained like `obj.add(X).add(Y).add(Z)`.
> However the test on line 92 fails and if I do a `writeln`, only
> "p1" and "p2" records show up.
>
> What am I missing here? Thanks in advance.
>
> [1]
> https://github.com/bahmanm/d-etudes/blob/master/source/e002/models.d
You should mark your return type with ref. Structs are value
types and therefore you return only a copy currently.
More information about the Digitalmars-d-learn
mailing list