Why retain new ?

Kirk McDonald kirklin.mcdonald at gmail.com
Sun Aug 5 17:40:36 PDT 2007


Alex Burton wrote:
> Given that all classes are on the heap, why not replace the syntax :
> CmdLin cl = new CmdLin(argc, argv);
> with
> CmdLin cl(argc,argv);
> saving some typing and repetition.
> 
> Only when casting to base class would you want to do :
> CmdLinBase cl = CmdLin(argc,argv);

You can already say this:

auto cl = new CmdLin(argc, argv);

The syntax you suggest looks too much like the C++ syntax for allocating 
on the stack. Using 'new' is more explicit, and makes it abundantly 
clear where the class is being allocated, and what its lifetime is.

-- 
Kirk McDonald
http://kirkmcdonald.blogspot.com
Pyd: Connecting D and Python
http://pyd.dsource.org



More information about the Digitalmars-d mailing list