#include <iostream>
using namespace std;
class Complex
{
public:
Complex(){real=0;imag=0;}
Complex(double r){real=r;imag=0;}
Complex(double r,double i){real=r;imag=i;}
operator double(){return real;}
void display();
private:
double real;
double imag;
};
void Complex::display()
{
cout<<"("<<real<<", "<<imag<<")"<<endl;
}
int main()
{
Complex c1(7,4),c2;
double d1;
d1=1.5+c1; //为避免二义性,强制为double类型
cout<<"d1="<<d1<<endl;
c2=Complex(d1);
cout<<"c2=";
c2.display();
return 0;
}
4.6
最新推荐文章于 2018-08-07 11:09:46 发布