Why are we not forced to instantiate a struct, like when using a class?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The why is simply – because the spec says so. The how is a matter of ensuring that the entire block of memory is “definitely assigned”, which means: assigning a value to each field of the struct. However, this requires 2 nasty things:
so in most best-practice cases, you do need to use the
new(...)syntax, to invoke the constructor (or to zero-the memory, for the parameterless constructor) for the type correctly.