struct
Why struct cannot declare a default constructor or destructor ?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jignesh TrivediPosted Apr 22, 2014, 5:30 AM
Destructor is used to destruct instances of classes and relase the resources. When you create new object of any class it will allocate memory on the heap.
when you create struct, it will create on stack memory because struct is value type. struct do not directly dealing with reference to any instance so struct have nothing to remove or destroy on Destructor. so Destructor is not supported with struct.
Struct is not support parameterless Constructor because struct is value type, compilers by default neither generate a default constructor, nor do they generate a call to the default constructor for value type.
VulpesPosted Apr 22, 2014, 5:15 AM