Prepare for your Next Interview
|
Welcome to the Geeks Talk forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
This is a discussion on constructor and destructor within the C and C++ forums, part of the Software Development category; What is the difference between constructor and destructor?...
|
|||||||
|
|||
|
constructor and destructor
What is the difference between constructor and destructor?
|
| The Following User Says Thank You to Sangeetha Poojary For This Useful Post: | ||
| Sponsored Links |
|
|||
|
Re: constructor and destructor
Constructor is used to initialize the class variable and create the object of the class.
Destructor is used to free the memory which was assigned to object while creating object. |
|
|||
|
Re: constructor and destructor
ya its same as the answer but slight modification in destructor.
constructor initilises the object where as destructor cleans up the object. and we need to define destructor if u have pointers and DMA |
|
|||
|
Re: constructor and destructor
Constructor is used to initialize variables. You can invoke a constructor becofe giving a call to any other method or program
Destructor is used to free the memomry by clearing up the variable values and setting them to NULL. |
|
|||
|
Re: constructor and destructor
Characterstics of Constructor:
1)They should be declared in the public section. 2)They are invoked automatically when the objects are created. 3)They do not have return types,not even void and therefore,they cannot return values. 4)They cannot be inherited.through a derived class can call the base class constructor. 5)Like other C++ function,they can have default argument. 6)Constructor cannot be virtual. 7)We cannot refer to their address. 8)an object with a constructor connot be used as a member of a union. 9)They make implicit calls to the operators new and delete when memory allocation is required. |
| The Following User Says Thank You to emrold.j For This Useful Post: | ||
|
|||
|
Re: constructor and destructor
[QUOTE=emrold.j;42034]Characterstics of Constructor:
1)They should be declared in the public section. 2)They are invoked automatically when the objects are created. 3)They do not have return types,not even void and therefore,they cannot return values. 4)They cannot be inherited.through a derived class can call the base class constructor. 5)Like other C++ function,they can have default argument. 6)Constructor cannot be virtual. 7)We cannot refer to their address. 8)an object with a constructor connot be used as a member of a union. 9)They make implicit calls to the operators new and delete when memory allocation is required. |
|
|||
|
Re: constructor and destructor
constructor has the same name as the class use to initiate the objects. destructor has the tild and the same name as the class use to free the memory. Destructor is by default executed by garbage collector.
|
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| constructor & destructor | Molugu Natraj | C and C++ | 6 | 05-10-2009 09:41 AM |
| constructor | emb.mallik | C and C++ | 1 | 03-02-2009 04:50 PM |
| Can a structure in C++ have a Constructor and Destructor | coolsomoo | C and C++ | 2 | 02-02-2009 07:45 AM |
| Constructor | kranti_435 | Java | 1 | 09-01-2008 08:47 AM |
| why i am getting an error while calling a constructor from another constructor | raj_java_j2ee | Java | 4 | 07-22-2007 03:39 AM |