#include <iostream.h>
class fract{
int x,y;
public:
fract(int xx,int yy)
{ x=xx;
y=yy;
}
operator double()//
{ return 1.0*x/y;//
}
void disp()
{ cout<<x<<"/"<<y<<endl;
}
};
int main()
{ fract f(3,4);
f.disp();
double d=f;//
cout<<d<<endl;
return 0;
}
//通过类型转换函数进行类型转换
//通过转换构造函数进行类型转换
#include <iostream.h>
class A{
public:
A(int n)
{ mm=n;
}
void disp()
{ cout<<mm<<endl;
}
private:
int mm;
};
int main()
{ A A1=A(5);
A1.disp();
A A2=6;
A2.disp();
return 0;
}