Thursday, May 7, 2009
Constructor Overloading
It is like functions we can use overloading constructors also, i.e. same constructor name with different arguments list based on argument data type the constructor will invoke.
header files
class num
{
int a,b;
float c,d;
char s[5], s1[10];
public:
num(int x, int y)// constructor overloading
{
a=x;
b=y;
}
num(char str[10], char str1[15])// constructor overloading
{
strcpy(s,s1);
strcpy(s1,str1);
}
num(float p) // constructor overloading
{
c=p;
d=555;
}
void display()
};
void num::display()
{
cout<
cout<
cout<
}
void main()
{
num obj(1000,5000);
num obj("Kumar","Dharsinisamy");
num obj(150.60);
obj.display();
}
Output will be
1000
5000
Kumar
Dharsinisamy
100.50
555
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
[フレーム]