www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Modify Object Pointer during Initialzation

reply "Jeroen Bollen" <jbinero gmail.com> writes:
This topic is somewhat related to this question I asked yesterday 
on StackOverflow: http://stackoverflow.com/q/22921395/2558778

Basically, why is this its own variable? Why doesn't D simply use 
the variable it was called with?

https://gist.github.com/Binero/10128826

I don't see why this needs to be a new variable and cannot simply 
be 'passed-by-reference'.
Apr 08 2014
parent reply "Adam D. Ruppe" <destructionator gmail.com> writes:
On Tuesday, 8 April 2014 at 14:04:01 UTC, Jeroen Bollen wrote:
 Basically, why is this its own variable? Why doesn't D simply 
 use the variable it was called with?
A class reference is basically a pointer, passing it by reference to each method would be a double pointer and wasted effort most the time; all most methods care about is where to get the object data, they don't need to know how the caller was getting to the object data.
 I don't see why this needs to be a new variable and cannot 
 simply be 'passed-by-reference'.
You can get that with UFCS btw: class A {} void f(ref A a) { /* modify a here and it will change */ } void main() { A a = new A; a.f; // a is passed by reference }
Apr 08 2014
parent reply "Jeroen Bollen" <jbinero gmail.com> writes:
On Tuesday, 8 April 2014 at 14:13:10 UTC, Adam D. Ruppe wrote:
 On Tuesday, 8 April 2014 at 14:04:01 UTC, Jeroen Bollen wrote:
 Basically, why is this its own variable? Why doesn't D simply 
 use the variable it was called with?
A class reference is basically a pointer, passing it by reference to each method would be a double pointer and wasted effort most the time; all most methods care about is where to get the object data, they don't need to know how the caller was getting to the object data.
 I don't see why this needs to be a new variable and cannot 
 simply be 'passed-by-reference'.
You can get that with UFCS btw: class A {} void f(ref A a) { /* modify a here and it will change */ } void main() { A a = new A; a.f; // a is passed by reference }
Is there a documentation page about the 'uniform function call syntax'?
Apr 08 2014
next sibling parent reply "Adam D. Ruppe" <destructionator gmail.com> writes:
On Tuesday, 8 April 2014 at 14:23:02 UTC, Jeroen Bollen wrote:
 Is there a documentation page about the 'uniform function call 
 syntax'?
http://dlang.org/function.html#pseudo-member
Apr 08 2014
parent "Jeroen Bollen" <jbinero gmail.com> writes:
On Tuesday, 8 April 2014 at 14:26:46 UTC, Adam D. Ruppe wrote:
 On Tuesday, 8 April 2014 at 14:23:02 UTC, Jeroen Bollen wrote:
 Is there a documentation page about the 'uniform function call 
 syntax'?
http://dlang.org/function.html#pseudo-member
Oh beat me to it.
Apr 08 2014
prev sibling parent "Jeroen Bollen" <jbinero gmail.com> writes:
On Tuesday, 8 April 2014 at 14:23:02 UTC, Jeroen Bollen wrote:
 Is there a documentation page about the 'uniform function call 
 syntax'?
Never mind, I think I understand all there is to it.
Apr 08 2014