digitalmars.D.learn - is Dlang support Uniform initialization like c++
- lili (9/9) Jun 30 2023 struct Point {
- Steven Schveighoffer (4/15) Jun 30 2023 You have to write `Point(4, 5)`. The advantage is we don't need to deal
- H. S. Teoh (5/16) Jun 30 2023 addPoint(Point(4,5), Point(4,6));
- =?UTF-8?Q?Ali_=c3=87ehreli?= (12/13) Jun 30 2023 In this case, arrays are better but only if you don't define a
struct Point { int x; int y; this(int x, int y) { this.x =x; this.y=y;} } void addPoint(Point a, Point b) { ... } How too wirte this: addPoint({4,5}, {4,6})
Jun 30 2023
On 6/30/23 11:18 AM, lili wrote:struct Point { int x; int y; this(int x, int y) { this.x =x; this.y=y;} } void addPoint(Point a, Point b) { ... } How too wirte this: addPoint({4,5}, {4,6})You have to write `Point(4, 5)`. The advantage is we don't need to deal with the complexity of C++ overloading rules. -Steve
Jun 30 2023
On Fri, Jun 30, 2023 at 03:18:41PM +0000, lili via Digitalmars-d-learn wrote:struct Point { int x; int y; this(int x, int y) { this.x =x; this.y=y;} } void addPoint(Point a, Point b) { ... } How too wirte this: addPoint({4,5}, {4,6})addPoint(Point(4,5), Point(4,6)); T -- "No, John. I want formats that are actually useful, rather than over-featured megaliths that address all questions by piling on ridiculous internal links in forms which are hideously over-complex." -- Simon St. Laurent on xml-dev
Jun 30 2023
On 6/30/23 08:18, lili wrote:How too wirte this: addPoint({4,5}, {4,6})In this case, arrays are better but only if you don't define a constructor, which you don't need for simple types like Point below: struct Point { int x; int y; } void main() { // The type is explicit on the left-hand side Point[] points = [ {1,2} ]; } Ali
Jun 30 2023