www.digitalmars.com         C & C++   DMDScript  

D - 'in', 'out', returning references?

reply skelly vatproducts.com writes:
I really like the use of "in" and "out" in argument lists, but
because then the purpose is documented in the code, but is there
a way to return a reference to an object besides using a pointer?

(Note, sometimes it is a builtin type, sometimes not.)

Sam
Apr 28 2004
next sibling parent J Anderson <REMOVEanderson badmama.com.au> writes:
skelly vatproducts.com wrote:

I really like the use of "in" and "out" in argument lists, but
because then the purpose is documented in the code, but is there
a way to return a reference to an object besides using a pointer?

(Note, sometimes it is a builtin type, sometimes not.)

Sam
  
If your talking about a primitive type (int, float ect..) or a struct, then without using out, and without using a pointer, no. If your talking about class objects, then these are already references (unlike C++ but like java). -- -Anderson: http://badmama.com.au/~anderson/
Apr 28 2004
prev sibling next sibling parent "Ivan Senji" <ivan.senji public.srce.hr> writes:
<skelly vatproducts.com> wrote in message
news:c6og8o$68h$1 digitaldaemon.com...
 I really like the use of "in" and "out" in argument lists, but
 because then the purpose is documented in the code, but is there
 a way to return a reference to an object besides using a pointer?
I also wish there was a way but there isn't :(
 (Note, sometimes it is a builtin type, sometimes not.)

 Sam
Apr 28 2004
prev sibling next sibling parent reply Andy Friesen <andy ikagames.com> writes:
skelly vatproducts.com wrote:
 I really like the use of "in" and "out" in argument lists, but
 because then the purpose is documented in the code, but is there
 a way to return a reference to an object besides using a pointer?
I'm not sure if this is what you're after, but it's perfectly legal to say 'Object* o'. It behaves like a pointer-pointer would in C++. -- andy
Apr 28 2004
parent Andy Friesen <andy ikagames.com> writes:
Andy Friesen wrote:

 skelly vatproducts.com wrote:
 
 I really like the use of "in" and "out" in argument lists, but
 because then the purpose is documented in the code, but is there
 a way to return a reference to an object *besides using a pointer?*
I'm not sure if this is what you're after, but it's perfectly legal to say 'Object* o'. It behaves like a pointer-pointer would in C++.
.... whups. Need more coffee. -- andy
Apr 28 2004
prev sibling parent reply "Matthew" <matthew.hat stlsoft.dot.org> writes:
Is it possible to return a struct which wraps a reference?

Doh! No. Structs do not have ctors/dtors.

Maybe that's another argument for it?

<skelly vatproducts.com> wrote in message news:c6og8o$68h$1 digitaldaemon.com...
 I really like the use of "in" and "out" in argument lists, but
 because then the purpose is documented in the code, but is there
 a way to return a reference to an object besides using a pointer?

 (Note, sometimes it is a builtin type, sometimes not.)

 Sam
May 07 2004
parent "Ivan Senji" <ivan.senji public.srce.hr> writes:
"Matthew" <matthew.hat stlsoft.dot.org> wrote in message
news:c7hcc0$2878$1 digitaldaemon.com...
 Is it possible to return a struct which wraps a reference?
To do this i wrote a class that wraps a value returned, but the problem is that the returned variable can only be accesed by property. I have something like ref!(int) func() { static int x; return new ref!(int)(x); } ... func().value=5;
 Doh! No. Structs do not have ctors/dtors.
But constructor can be simulated with opCall. I don't undestand how you mean a struct wraping a reference?
 Maybe that's another argument for it?

 <skelly vatproducts.com> wrote in message
news:c6og8o$68h$1 digitaldaemon.com...
 I really like the use of "in" and "out" in argument lists, but
 because then the purpose is documented in the code, but is there
 a way to return a reference to an object besides using a pointer?

 (Note, sometimes it is a builtin type, sometimes not.)

 Sam
May 08 2004