+ 5

Can a struct have destructors?

Eg - Can this code work? enum{dead=0,alive}; struct Person { private: int state; public: Person(){state=alive;} //This gave no errors though... string name; string address; void kill(){state=dead;} ~Person(){} //This returns an error }

3rd Apr 2017, 9:47 AM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
9 Réponses
+ 5
There is a difference b/w C and C++ Structures...
3rd Apr 2017, 11:43 AM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 4
@surya kumar No, structures are there in c++ If not, why does this code work without the destructor?
3rd Apr 2017, 11:09 AM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 1
OK wait I I'll be check and then tell u
3rd Apr 2017, 11:11 AM
surya kumar
surya kumar - avatar
+ 1
Structure is a collection of variables of different data types under a single name but we can't use Herr any functions inside class
3rd Apr 2017, 11:29 AM
surya kumar
surya kumar - avatar
+ 1
sort inside struct
3rd Apr 2017, 11:29 AM
surya kumar
surya kumar - avatar
+ 1
but if u use class u can use constructor destructor and functions inside the class and also access spcifier
3rd Apr 2017, 11:30 AM
surya kumar
surya kumar - avatar
+ 1
no diffrece bcoz cpp is developed fromm c so wt it's supported by CPP .and the advance of strict,union,etc is called by as class in cpp
3rd Apr 2017, 11:53 AM
surya kumar
surya kumar - avatar
0
c++ doesn't had struct instead of this it has a class
3rd Apr 2017, 11:07 AM
surya kumar
surya kumar - avatar
0
at kind of error u got
3rd Apr 2017, 11:09 AM
surya kumar
surya kumar - avatar