+ 4

How the constructors and destructors are used in real time applications?

12th Jan 2017, 6:33 AM
Anvesh
Anvesh - avatar
4 Respostas
+ 5
deconstructors are a good place for destroying unmanaged pointers..
12th Jan 2017, 7:44 AM
jay
jay - avatar
+ 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.
12th Jan 2017, 6:48 AM
Dao
Dao - avatar
+ 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.
12th Jan 2017, 12:11 PM
Nathan
Nathan - avatar
+ 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
29th Jan 2017, 9:14 AM
Dhiraj Ramteke
Dhiraj Ramteke - avatar