www.digitalmars.com         C & C++   DMDScript  

D - Return value from constructor

reply "Martin M. Pedersen" <mmp www.moeller-pedersen.dk> writes:
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
Jun 14 2002
parent reply "Walter" <walter digitalmars.com> writes:
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
Jun 14 2002
parent "Sean L. Palmer" <seanpalmer earthlink.net> writes:
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
Jun 15 2002