Struct
Why struct cannot declare a default constructor or destructor ?
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
VulpesRank #55 · 29.2K reputationPosted Apr 22, 2014, 1:15 AM EDT
Jignesh TrivediRank #16 · 50.3K reputationPosted Apr 22, 2014, 1:30 AM EDT
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.