Thread overview
Return value from constructor
Jun 14, 2002
Martin M. Pedersen
Jun 15, 2002
Walter
Jun 15, 2002
Sean L. Palmer
June 14, 2002
Hi,

It seems that constructors has a return type. The class Good below compiles, but Bad does not.:

    /*
    class Bad
    {
        this()
        {
            return; // causes "return value expected"
        }
    }
    */

    class Good
    {
        this()
        {
            return this; // compiles fine
        }
    }


It can't be right, can it?

Regards,
Martin M. Pedersen






June 15, 2002
I'll  have to think about that one!

"Martin M. Pedersen" <mmp@www.moeller-pedersen.dk> wrote in message news:aedpad$rma$1@digitaldaemon.com...
> Hi,
>
> It seems that constructors has a return type. The class Good below
compiles,
> but Bad does not.:
>
>     /*
>     class Bad
>     {
>         this()
>         {
>             return; // causes "return value expected"
>         }
>     }
>     */
>
>     class Good
>     {
>         this()
>         {
>             return this; // compiles fine
>         }
>     }
>
>
> It can't be right, can it?
>
> Regards,
> Martin M. Pedersen
>
>
>
>
>
>


June 15, 2002
Could be an interesting way to do a kind of "operator new".

I've toyed with that and so far nothing has turned up that looked good.  But it has potential.

Sean

"Walter" <walter@digitalmars.com> wrote in message news:aeelqn$1mk7$1@digitaldaemon.com...
> I'll  have to think about that one!
>
> "Martin M. Pedersen" <mmp@www.moeller-pedersen.dk> wrote in message news:aedpad$rma$1@digitaldaemon.com...
> > Hi,
> >
> > It seems that constructors has a return type. The class Good below
> compiles,
> > but Bad does not.:
> >
> >     /*
> >     class Bad
> >     {
> >         this()
> >         {
> >             return; // causes "return value expected"
> >         }
> >     }
> >     */
> >
> >     class Good
> >     {
> >         this()
> >         {
> >             return this; // compiles fine
> >         }
> >     }
> >
> >
> > It can't be right, can it?
> >
> > Regards,
> > Martin M. Pedersen