Is there any way to prevent the default constructor of a struct to be called?
I have several structs in my project and some of them I can not let the default constructor to be called at any circumstances (that will be cause a lot of unwanted behaviour in my code).
PS.: Any solution that just indicates me when coding that some of that special structs (that can not be instantiated with the default constructor) are being instantiate "wrongly" is fine for me. A simple compiler warning should be enough for my case!
You cannot.
By nature,
struct
must be initialized to some value.struct
cannot have a parameter-less constructorEither use a class
if you need such behavior or review your design.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With