Thread overview
How to return the current object
Sep 26, 2011
alex
Sep 26, 2011
Ali Çehreli
Sep 27, 2011
Nick Sabalausky
September 26, 2011
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
September 26, 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 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
September 27, 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 work

Main isn't a member of any object, so there is no "this" inside main.