Programming in D page 295 - disable default constructor
monkyyy
crazymonkyyy at gmail.com
Tue Feb 10 12:50:16 UTC 2026
On Tuesday, 10 February 2026 at 12:04:05 UTC, Brother Bill wrote:
> When adding an explicit constructor such as ```this(string
> fileName)```, this is "supposed" to remove the "default"
> constructor. Then the developer needs to add back the default
> constructor.
>
> [...]
```d
import std;
struct foo{
int i,j;
this(int a, int b){
j=a;
i=b;
}
}
unittest{
auto bar=foo(1,2);
bar=foo(3);
}
```
> Error: constructor `onlineapp.foo.this(int a, int b)` is not
> callable using argument types `(int)`
working as expected
More information about the Digitalmars-d-learn
mailing list