Object conversion
#include "stdio.h"
class ObjectConversion
{
public:
ObjectConversion() { }
~ObjectConversion(){ }
operator int() { return 10; }
operator double(){ return 12.002; }
};
void ObjectConversionClient()
{
ObjectConversion obj;
int i ;
double d;
i = obj;
d = obj;
printf("\n value of i is %d",i);
printf("\n value of d is %lf",d);
}
int main(int argc, char* argv[])
{
ObjectConversionClient();
return 0;
}
The output for this program is :
value of i is 10
value of d is 12.00200
class ObjectConversion
{
public:
ObjectConversion() { }
~ObjectConversion(){ }
operator int() { return 10; }
operator double(){ return 12.002; }
};
void ObjectConversionClient()
{
ObjectConversion obj;
int i ;
double d;
i = obj;
d = obj;
printf("\n value of i is %d",i);
printf("\n value of d is %lf",d);
}
int main(int argc, char* argv[])
{
ObjectConversionClient();
return 0;
}
The output for this program is :
value of i is 10
value of d is 12.00200
Labels: Cpp
0 Comments:
Post a Comment
<< Home