+ 4
How the constructors and destructors are used in real time applications?
4 ответов
+ 5
deconstructors are a good place for destroying unmanaged pointers..
+ 3
I personally haven't found much use for destructors yet, but constructors are really good for ensuring you already have the minimum amount of necessary data whenever you're creating an instance of the object at hand. Of course, it's your own responsibility to make sure the data you're using is valid, as an object construction cannot fail, but that's another topic entirely.
+ 2
Following up with what Jay said, the destructor is used to clean-up any resources that are owned by the class.
For instance, if the class has members that are accessed through pointers (directly or with a list/array/map/etc), if the class uses any O/S level resources (files, message queues, handles), or if the classes has a connection to an external device -- the destructor is the right place to make sure these are all cleaned up properly.
+ 1
Basically constructor is use to initialize the value ,so we can use it for initialize value.And destructor is use for deallocate the memory to the variable