Stop using the enum as a manifest constant.

Jack Applegame japplegame at gmail.com
Sun Jun 6 11:16:29 UTC 2021


On Sunday, 6 June 2021 at 10:47:54 UTC, Mathias LANG wrote:
> I wouldn't go that far. `enum` are like `#define`, and there 
> *are* cases where you want them. E.g. when using them as define 
> arguments:
> ```D
> void foo (char[] fmt = DEFAULT_VALUE) { /* ... */ }
> ```
>
> If `DEFAULT_VALUE` is `immutable`, this will never compile, but 
> with `enum`, it might.

Really?
```d
enum DEFAULT_VALUE = "aaaa";
void foo (char[] fmt = DEFAULT_VALUE) {} // Error: cannot 
implicitly convert expression `"aaaa"` of type `string` to 
`char[]`
```



More information about the Digitalmars-d mailing list