Eliminate "new" for class object creation?
Kagamin
spam at here.lot
Tue Oct 20 00:27:28 PDT 2009
Andrei Alexandrescu Wrote:
> I'm having a hard time justifying that you use
>
> new X(args)
>
> to create a class object, and
>
> X(args)
>
> 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
> place.
> ===============
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.
More information about the Digitalmars-d
mailing list