Suggestion: shortcut for 'new X'

Ivan Senji ivan.senji_REMOVE_ at _THIS__gmail.com
Fri Aug 25 02:24:37 PDT 2006


Rémy J. A. Mouëza wrote:
> 
>>> Kristian wrote:
>>> Consider the following:
>>>
>>> Obj func2() {...}
>>>
>>> void func() {
>>>      auto obj = func2();
>>> }
> 
> For such cases, there is the typeof() operator :
> 
> Obj func2 () { ... }
> 
> void func ()
> {    typeof ( func2 ) obj = func2 ();
> }

Why that when this works:

void func() {
      auto obj = func2();
}

What I think Kristian was saying is that you cannot see the type from 
the above, but you can know the type if it is:

Obj obj1 = func2();
Obj obj1 = new;

While it does make sense, I don't think that "auto obj = func2();" is a 
big problem and prefer auto.



More information about the Digitalmars-d mailing list