Session - 6 - C++ Constructors - and - Destructors
Session - 6 - C++ Constructors - and - Destructors
&
Destructors
Constructors
A Member function with the same name as its
classis called Constructor and it is used to
initilize the objects of that class type with a legal
value.
A Constructor is a special member function of a
class that is called automatically when an object
of class is created.
Example :
class Student
{
int rollno;
float marks;
public: // Implicit Call
student( ) //Constructor Student ob1;
{
// Explicit Call
rollno=0; Student ob1=student();
marks=0.0;
}
//other public members
};
TYPES OF CONSRUCTORS
1. Default Constructor: A constructor that accepts no
parameter is called the Default Constructor. If you don't
declare a constructor or a destructor, the compiler makes
one for you. The default constructor and destructor take
no arguments and do nothing.