Re: D Classes Passed By Reference or Value?

2015-08-16 Thread Nicholas Wilson via Digitalmars-d-learn
On Sunday, 16 August 2015 at 23:40:41 UTC, Brandon Ragland wrote: On Sunday, 16 August 2015 at 23:31:46 UTC, Ali Çehreli wrote: On 08/16/2015 04:13 PM, Brandon Ragland wrote: > That makes more sense. Though it does make the ref method > signature unclear, as it only applies to literals at this

Re: D Classes Passed By Reference or Value?

2015-08-16 Thread Brandon Ragland via Digitalmars-d-learn
On Sunday, 16 August 2015 at 23:31:46 UTC, Ali Çehreli wrote: On 08/16/2015 04:13 PM, Brandon Ragland wrote: > That makes more sense. Though it does make the ref method > signature unclear, as it only applies to literals at this > point? As long as the returned object will be valid after the fu

Re: D Classes Passed By Reference or Value?

2015-08-16 Thread Ali Çehreli via Digitalmars-d-learn
On 08/16/2015 04:13 PM, Brandon Ragland wrote: > That makes more sense. Though it does make the ref method > signature unclear, as it only applies to literals at this > point? As long as the returned object will be valid after the function leaves, it can be anything: one of the ref parameters,

Re: D Classes Passed By Reference or Value?

2015-08-16 Thread Brandon Ragland via Digitalmars-d-learn
On Sunday, 16 August 2015 at 22:35:15 UTC, Alex Parrill wrote: On Sunday, 16 August 2015 at 22:31:02 UTC, Brandon Ragland wrote: Hi All, I'm a bit confused as to how Classes in D are passed in arguments and returns. Take this for example: class MyClass{ int x = 2; } And then in app.d ref My

Re: D Classes Passed By Reference or Value?

2015-08-16 Thread Alex Parrill via Digitalmars-d-learn
On Sunday, 16 August 2015 at 22:31:02 UTC, Brandon Ragland wrote: Hi All, I'm a bit confused as to how Classes in D are passed in arguments and returns. Take this for example: class MyClass{ int x = 2; } And then in app.d ref MyClass doStuff(){ MyClass mc = new MyClass() // Heap allocation,

Re: D Classes Passed By Reference or Value?

2015-08-16 Thread Alex Parrill via Digitalmars-d-learn
On Sunday, 16 August 2015 at 22:31:02 UTC, Brandon Ragland wrote: ref MyClass doStuff(){ MyClass mc = new MyClass() // Heap allocation, using new return mc; } This attempts to return a reference to the _variable_ `mc`, not a reference to the class. Just remove `ref` from the function sig

D Classes Passed By Reference or Value?

2015-08-16 Thread Brandon Ragland via Digitalmars-d-learn
Hi All, I'm a bit confused as to how Classes in D are passed in arguments and returns. Take this for example: class MyClass{ int x = 2; } And then in app.d ref MyClass doStuff(){ MyClass mc = new MyClass() // Heap allocation, using new return mc; } The above fails, as "escaping reference