Suggestion: shortcut for 'new X'

Chris Nicholson-Sauls ibisbasenji at gmail.com
Thu Aug 24 13:09:32 PDT 2006


Kristian wrote:
> How about this:
> 
>     Obj obj1 = new Obj;
>     Obj obj2 = new Obj(10);
> 
> could be reduced to:
> 
>     Obj obj1 = new;
>     Obj obj2 = new(10);
> 
> This way only one class name would be required per variable. (That is, 
> one  at maximum: "Obj obj1 = new, obj2 = new(10);" is also valid of 
> course.)  Redundance would be reduced.
> 
> I know, it looked quite 'odd' for me too at first, but now it looks 
> very  natural, and even clearer than the longer way.
> 
> 
> I'm not sure if using of this syntax should be possible outside the  
> variable declarations. Later in a code "obj1 = new;" is less 
> informative  than "obj1 = new Obj;". However, someone may like it too... 
> it's up to a  programmer how to code (which is not always a good 
> thing(tm) though).

Would this pose any ambiguities with custom class allocators?

-- Chris Nicholson-Sauls



More information about the Digitalmars-d mailing list