Geeks Talk

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.

constructor and destructor

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?...

Go Back   Geeks Talk > Software Development > C and C++
Register Blogs FAQ Tag Cloud Calendar Mark Forums Read
  #1 (permalink)  
Old 12-31-2008
Junior Member
 
Join Date: Dec 2008
Location: mumbai
Posts: 1
Thanks: 0
Thanked 1 Time in 1 Post
Sangeetha Poojary is on a distinguished road
constructor and destructor

What is the difference between constructor and destructor?
Reply With Quote
The Following User Says Thank You to Sangeetha Poojary For This Useful Post:
Sponsored Links
  #2 (permalink)  
Old 01-02-2009
Junior Member
 
Join Date: Dec 2008
Posts: 12
Thanks: 0
Thanked 2 Times in 2 Posts
chetanchauahan10 is on a distinguished road
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.
Reply With Quote
  #3 (permalink)  
Old 02-03-2009
Junior Member
 
Join Date: Feb 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
chaamurah is on a distinguished road
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
Reply With Quote
  #4 (permalink)  
Old 02-03-2009
Expert Member
 
Join Date: Nov 2008
Location: Chennai
Posts: 303
Thanks: 1
Thanked 37 Times in 32 Posts
amitpatel66 is on a distinguished road
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.
Reply With Quote
  #5 (permalink)  
Old 03-01-2009
Junior Member
 
Join Date: Feb 2009
Location: Jodhpur,Rajasthan
Posts: 2
Thanks: 0
Thanked 1 Time in 1 Post
emrold.j is on a distinguished road
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.
Reply With Quote
The Following User Says Thank You to emrold.j For This Useful Post:
  #6 (permalink)  
Old 03-01-2009
Junior Member
 
Join Date: Feb 2009
Location: Jodhpur,Rajasthan
Posts: 2
Thanks: 0
Thanked 1 Time in 1 Post
emrold.j is on a distinguished road
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.
Reply With Quote
  #7 (permalink)  
Old 03-22-2009
Junior Member
 
Join Date: Mar 2009
Location: chennai
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
shalini vijay is on a distinguished road
Re: constructor and destructor

the specially linked attributes which are used in the under the same name, in which they have the access to the different member of the same.
Reply With Quote
  #8 (permalink)  
Old 03-28-2009
Junior Member
 
Join Date: Mar 2009
Location: SAHARSA
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
nikki _niharika is on a distinguished road
Re: constructor and destructor

Constructor is used to initialize the variables and destructor is used to free the memory of that variables.
Reply With Quote
  #9 (permalink)  
Old 04-06-2009
Junior Member
 
Join Date: Oct 2007
Location: Pune
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
paragvb is on a distinguished road
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.
Reply With Quote
Reply

  Geeks Talk > Software Development > C and C++

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


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


All times are GMT -4. The time now is 09:05 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.3.1
Copyright © 2009 GeekInterview.com. All Rights Reserved