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