class class-name{
access label:
data members;
member functions;
class-name();//constructor
}
class employee{
private:
int employee_id;
char name[20];
float salary;
public:
employee(){
employee_id=10;
strcpy(name, “ashok’’);
salary=5000;
}
void getdata();
}ob1,ob2;
class-name::class-name
{
body of the constructor function;
}
Example
class creature{
private:
int yearofbirth;
public:
creature(){
cout<<"constructor called";
};
main(){
creature obj;
getch();
return 0;
}
Example
class creature{
private:
int yearofbirth;
public:
creature(int year){
year=yearofbirth;
}
};
Example
class abc{
int a;
float b;
public:
void fun();
abc(int x, float y){
a=x;
b=y;
}
abc(abc &dob){
a=dob.a;
b=dob.b;
}
};