Suggestion: shortcut for 'new X'
Sean Kelly
sean at f4.ca
Thu Aug 24 14:01:46 PDT 2006
Chris Nicholson-Sauls wrote:
> 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?
I was wondering the same thing, but I think it could be resolved via
look-ahead. That said, I'm not sure I like the syntax as it seems a bit
confusing. Is it really so hard to specify the type name?
Sean
More information about the Digitalmars-d
mailing list