www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How to return the current object

reply alex <ask nospam.com> writes:
Is there a way to return the current object in any part of the code, 
even from void main? (which is still a type void). I have tried the this 
thing but it doesn't work
-- 
Alex Herrmann
PC load letter
Sep 25 2011
next sibling parent Ali =?iso-8859-1?q?=C7ehreli?= <acehreli yahoo.com> writes:
On Sun, 25 Sep 2011 20:20:59 -0600, alex wrote:

 Is there a way to return the current object in any part of the code,
I presume you mean returning self from a member function: class C { C foo() { return this; } C bar() { return this; } } void main() { auto o = new C; o.foo().bar(); }
 even from void main? (which is still a type void). I have tried the this
 thing but it doesn't work
No, you can't return any object from main if the return type is void. You may define main as returning int, to communicate the termination status of the program to the environment that started it: int main() { return 0; } Ali
Sep 25 2011
prev sibling parent "Nick Sabalausky" <a a.a> writes:
"alex" <ask nospam.com> wrote in message 
news:j5onj9$2f85$1 digitalmars.com...
 Is there a way to return the current object in any part of the code, even 
 from void main? (which is still a type void). I have tried the this thing 
 but it doesn't work
Main isn't a member of any object, so there is no "this" inside main.
Sep 27 2011