Default arguments

Salih Dincer salihdb at hotmail.com
Tue Feb 7 22:05:39 UTC 2023


On Tuesday, 7 February 2023 at 09:49:46 UTC, Salih Dincer wrote:
> Is it a feature or a bug that the code below can be compiled 
> without arguments?

You should use `@disable this()` recommended in the relevant 
article: 
https://dlang.org/spec/struct.html#disable_default_construction

```d
void main()
{
     auto noArgument = Sarr!char(); // no compile
}
```

On Tuesday, 7 February 2023 at 09:49:46 UTC, Salih Dincer wrote:
> I want to learn one more thing. Why can't the default argument 
> be used in alias of structs?

```d
void main()
{
     auto bar = Sarr!()(dlang.dup); // complied
     assert(is(typeof(bar.arr[0]) == char));
}
```
😀

SDB at 79




More information about the Digitalmars-d-learn mailing list