Aim:
Write a program to demonstrate the typecasting
of class type to basic type.
Ans:
#include<iostream.h>
#include<conio.h>
class A
{
int x,y;
public:
A()
{
cout<<"Enter
the values which you want to add:\n";
cin>>x>>y;
}
operator
int()
{
int
z;
z=x+y;
return(z);
}
};
void main()
{
clrscr();
A o;
int k=o;
cout<<"Sum is:"<<k;
getch();
}
No comments:
Post a Comment