Constructors are special member functions which are executed automatically when object of a class is created. These are special because they have same name as name of class. These are also special because they do not have any return type.
Syntax:
class-name(parameter list)
{
...
}
Eg:
#include<iostream.h>
#include<conio.h>
class abc
{
int a,b;
public:
abc()
{
a=0;
b=0;
}
void show()
{
cout<<"a= "<<a<<endl<<"b= "<<b<<endl;
}
};
void main()
{
clrscr();
abc ob;
ob.show();
getch();
}
Types of Constructors in C++:
No comments:
Post a Comment