hits counter
  Create Free Blog | Random Blog »   Report Abuse | Login   

 

Archive for the 'Constructor and destructors' Category

Copy Constructor

*One of the more important forms of an overloaded constructor is the copy constructor.
*A copy constructor take a reference to an object of the same class as itself as an argument.
*Once defined,the copy constructor is called whenever an object is to initialize another.
*The copy constructor only applies to initializations.It does not apply to assignments.
*The most [...]

Constructor overloading

Parameterized constructor
Constructors that take arguments are called as parameterized constructor.
Constructor overloading:
*It is possible to overload a class’s constructor function. i.e., More than one constructors declared with in a single class.
*Reasons to overload constructor function:
1.To gain flexibility
2.To support arrays
3.To create copy constructor
Program:
#include<iostream.h>
class Time
{
int Hr,Min;
public:
Time() //No Argument Constructor(default)
{
Hr=0;
Min=0;
}
Time(int H,int M) //Two Argument(int type) Constructor
{
Hr=H;
Min=M;
}
Time (float T) [...]

Constructor and destructor functions

Constructor
Constructor is a special type member function,which execute automatically whenever an object is created.
Rules of creating Constructor:
*Name              :Constructor name is same as class name.
*Scope              :Public
*Return Type    :Nil
*Argument       :Optional
*Overloading   :Possible
Use:
*Variable Initialization
*Resource Allocation
*Type Conversion
Destructor
Destructor is a special type member function,which execute automatically whenever an object is destroyed.
Rules for creating Destructor:
*Name             :Destructor name is same as class name [...]