Parens

Ty Tower towerty at msn.com.au
Sat May 10 01:35:22 PDT 2008


Dee Girl Wrote:

> Janice Caron Wrote:
> 
> > On 10/05/2008, Dee Girl <deegirl at noreply.com> wrote:
> > >  void main(string[] args)
> > >  {
> > >     auto c = new const C;
> > >  }
> > >
> > >  Does not compile. But if I change to const(C) it does compile. It is a bit unusual that parens make such a big difference. Thank you, Dee Girl
> > 
> > When it comes to parens-version versus non-parens-version, it's not
> > really a problem if one of the two doesn't compile. It would be a
> > bigger problem if both compile, but behave differently.
> > 
> > But I agree with you. "new const C" should behave like "new const(C)".
> > 
> > However, what you probably should have written is:
> > 
> >     const c = new C;
> > 
> > because "auto" is what you use in the absence of any other attribute.
> > In this case, it suffices to create a new C, and then assign it to a
> > const-thereafter variable.
> 
> I respectfully disagree, Janice-san. The const subject is of big interest to me and I read many times on the website about it. I think in general it is better to write new const(C) but not new C and then use it to assign a const. It is similar to invariant(C) and it is impossible to construct a new C and then assign it to invariant(C) object. In Andres document from ACCU he shows how invariant constructor must know that object being constructed is invariant. And the same a const constructor could know that the object being constructed is const and use that information. Thank you, Dee Girl


Ahh the Japs . Exponents of the art of seeming respectful whilst telling you you are a bloody idiot . This ones not so good at it though.





More information about the Digitalmars-d mailing list