标签:eal return 运算符 tor double 强制 code lex turn
源程序:
#include<iostream>
using namespace std;
class myComplex
{
double real,imag;
public:
myComplex(double r=0,double i=0):real(r),imag(i){};
operator double() //重载强制类型转换运算符double
{
return real;
}
};
int main()
{
myComplex c(1.2,-3.4);
cout<<(double)c<<endl;
double n=12+c; //实部相加
cout<<n<<endl;
return 0;
}
运行结果:
标签:eal return 运算符 tor double 强制 code lex turn
原文地址:https://www.cnblogs.com/duanqibo/p/12259147.html