J
John Cho
Class Cartesian
{ double x;
double y;
public:
Cartesian( ) { x = 0.0 ; y = 0.0;}
Cartesian(double x1, double y1)
{ x = x1; y = y1;}
};
class Polar
{ double radius;
double angle;
public:
Polar( ) { radius = 0.0; angle = 0.0;}
Polar(double r, double a) { radius = r; angle = a;}
//Use operator conversion function to convert Polar to Cartesian
operator Cartesian( )
{ double xx, yy;
xx = radius * cos(angle);
yy = radius * sin(angle);
return Cartesian(xx, yy);
}
};
that operator Cartesian, converts class Polar to Cartesian
via
Polar P;
Cartesian C;
C = P;
i am wondering about the
return Cartesian(xx, yy);
why is it that and not
return (Cartesian c2(xx, yy));
why is it just returning a constructor? that just does not make sense to
me
{ double x;
double y;
public:
Cartesian( ) { x = 0.0 ; y = 0.0;}
Cartesian(double x1, double y1)
{ x = x1; y = y1;}
};
class Polar
{ double radius;
double angle;
public:
Polar( ) { radius = 0.0; angle = 0.0;}
Polar(double r, double a) { radius = r; angle = a;}
//Use operator conversion function to convert Polar to Cartesian
operator Cartesian( )
{ double xx, yy;
xx = radius * cos(angle);
yy = radius * sin(angle);
return Cartesian(xx, yy);
}
};
that operator Cartesian, converts class Polar to Cartesian
via
Polar P;
Cartesian C;
C = P;
i am wondering about the
return Cartesian(xx, yy);
why is it that and not
return (Cartesian c2(xx, yy));
why is it just returning a constructor? that just does not make sense to
me