Old code no longer working on any DMD compilers
Mike Parker
aldacron at gmail.com
Fri Sep 6 06:53:21 UTC 2019
On Friday, 6 September 2019 at 05:59:30 UTC, Jamie wrote:
> time and fmod is called so it breaks. In case 3, with default
> struct arguments, I thought that the constructor I have defined
> was being called, however the default constructor was being
> called (this()) so fmod wasn't being called.
>
> The reason why my old code worked was because it used the
> default arguments and I wasn't actually calling the constructor
> I defined. When I removed the default arguments in the
> constructor and tried case 2 it obviously didn't work.
>
> Am I understanding correctly? Thanks
You're right about case 1 and case 2, and partially correct about
case 3. Structs don't actually have default constructors. They
have default *initializers*. In other words, s = S() is the same
as s = S.init. See item #4 in the documentation for struct
destructors [1]:
"If the ParameterList is empty, the struct instance is default
initialized."
So yes, your constructor is not being called.
1. https://dlang.org/spec/struct.html#struct-constructor
More information about the Digitalmars-d-learn
mailing list