digitalmars.D.learn - How to return the current object
- alex (6/6) Sep 25 2011 Is there a way to return the current object in any part of the code,
- Ali =?iso-8859-1?q?=C7ehreli?= (26/29) Sep 25 2011 I presume you mean returning self from a member function:
- Nick Sabalausky (3/6) Sep 27 2011 Main isn't a member of any object, so there is no "this" inside main.
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
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 workNo, 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
"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 workMain isn't a member of any object, so there is no "this" inside main.
Sep 27 2011