www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Re: Eliminate "new" for class object creation?

Andrei Alexandrescu Wrote:

 I'm having a hard time justifying that you use
 new X(args)
 to create a class object, and
 to create a struct object. I wrote this:
 The syntactic  difference between  the expression creating  a  struct 
 object---Test( \meta{args} ) ---and the  expression creating a  class 
 object---\cc{new Test(}\meta{args} ) ---may be  jarring at first. \dee
 could have dropped the  new   keyword entirely, but that  new  reminds
 the programmer that an object allocation (i.e., nontrivial work) takes

That's struct literal, not struct object. Struct object is on the left hand side. Struct literal calling the constructor looks more like a hack, C++ looks more consistent in this aspect. And you can create a struct object with new operator.
Oct 20 2009