Overloading based on named arguments is possible, here’s how
cc
cc at nevernet.com
Wed May 8 04:46:26 UTC 2024
On Tuesday, 7 May 2024 at 11:58:59 UTC, Quirin Schroll wrote:
> Then, the two constructors have different mangles and can be
> distinguished in the object file. In code, using named
> arguments, one can re-order the parameters and because the enum
> parameters are defaulted, they need no arguments.
Interesting! Looks like this can be done via template arguments
as well.
```d
struct X {
this(string f = "x")(int x) { writeln("X(int x) called with ",
x); }
this(string f = "y")(int y) { writeln("X(int y) called with ",
y); }
}
X(x: 1); // X(int x) called with 1
X(y: 2); // X(int y) called with 2
```
More information about the Digitalmars-d
mailing list