Super easy struct construction question that I'm embarrassed to ask.

Ali Çehreli acehreli at yahoo.com
Mon Jan 13 18:30:15 UTC 2025


On 1/12/25 8:55 PM, H. S. Teoh wrote:

 > I wish there was some kind of syntactic sugar for assigning ctor
 > parameters to class members.

Amen. Dart provides some help. It's under Generative Constructors here:

   https://dart.dev/language/constructors

class Point {
   // Instance variables to hold the coordinates of the point.
   double x;
   double y;

   // Generative constructor with initializing formal parameters:
   Point(this.x, this.y);
}

The following comment under the next section hints at what happens when 
a constructor body is provided:

   // Sets the x and y instance variables
   // before the constructor body runs.

Ali



More information about the Digitalmars-d-learn mailing list