Constructor in C++
Constructor
Example:
class a
{
int b,c;
public:
a(void); //constructor declare
....................
...................
};
a :: a(void) //constructor defined
{
b=0;
c=10;
}
Characteristics Of Constructor:
- Constructor is a'special' member function.
- Name of constructor and class is always same.
- Constructor invoked when we create class.
- It's called constructor because it construct the value of data member in the class.
Example:
class a
{
int b,c;
public:
a(void); //constructor declare
....................
...................
};
a :: a(void) //constructor defined
{
b=0;
c=10;
}
Characteristics Of Constructor:
- Constructor should be declare in public section.
- Constructor are invoked automatically when object is created.
- Constructor do not have any datatype.
- Constructor cannot be inherited.
- Constructor have default argument like functions.
- Constructor cannot be virtual.
Types Of Constructors:
- Default Constructor
- Parameterized Constructor
- Copy Constructor
- Dynamic Constructor
0 Comments