Total members 10249 | Gratitudes |It is currently Thu May 17, 2012 8:40 am Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 1 post ] 
Author Question
 Question subject: What are Constructors and Destructors?
PostPosted: Wed Jul 04, 2007 12:41 am 
Offline
Beginner
User avatar

Joined: Wed Mar 28, 2007 1:17 pm
Posts: 118
Location: Cairo-Egypt
Has thanked: 0 time
Have thanks: 5 time

What are Constructors and Destructors?
----------------------------------------------------------------


Constructors from a conceptual level enable the creation of an object of a given class- a constructor is a method of a class with no return parameters. Constructors also enable the initialization of any variables of a class; you can supply input parameters to constructors. Constructors can have access modifiers- Private, Protected and Public.

A constructor gets called automatically when you create an object of a class; if you donط£آ¢أ¢â€ڑآ¬أ¢â€‍آ¢t define your own constructor, by default a constructor is called which is the Default Constructor. A class can have more than one constructor. It has the same name as the class itself.

Destructors are again methods of a class that enable the destruction of an object after its use; destructors also provide the means of memory clean up after usage. Destructors are always called in the reverse order of Constructors. There can only be one destructor per class and they neither take an input parameter nor do they return anything. Destructors need not be called explicitly.

Code:
class Vehicle
{
   Int Registration = 0;
   public:
   Vehicle(int regis) // constructor
   {
      Registration =  regis;
   }
   Virtual void GetRegistration() = 0;
   ~Vehicle()  // destructor
       {     
       }
};

Thanks alot


TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 1 post ] 
Quick reply


  

 Similar topics
 Class constructors

All times are UTC [ DST ]


Users browsing similar posts

Users browsing this forum: No registered users and 1 guest



Jump to:  
Previous Question | Next Question 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team