In type conversion of 2 different classes can i convert both ways ?
-
i want to make a program that can convert from class a type to class b & vice versa.. i already made a program that does one type of conversion..
//define 2 classes polar & rectangle to represent points int the polar & rectanglular system.
#include
#include
using namespace std;class Polar;
//====================================================
class Rectangle{
float length, bredth;
public:
Rectangle(){}
Rectangle(float ,float);/\* operator Polar(){ Polar temp; float a = atan(length/bredth), r = sqrt(x\*x + y\*y); temp.getAngle(a); temp.getRadius(r); return(temp); } \*/ int getLength(){return(length);} int getBredth(){return(bredth);} void putLength(float x){length = x;} void putBredth(float y){bredth = y;} void putData(){cout<<"Length : "<
as in the above code i have converted class Polar to class Rectangle, but i also want to have a conversion of class Rectangle to class Polar.
Thank you
-
i want to make a program that can convert from class a type to class b & vice versa.. i already made a program that does one type of conversion..
//define 2 classes polar & rectangle to represent points int the polar & rectanglular system.
#include
#include
using namespace std;class Polar;
//====================================================
class Rectangle{
float length, bredth;
public:
Rectangle(){}
Rectangle(float ,float);/\* operator Polar(){ Polar temp; float a = atan(length/bredth), r = sqrt(x\*x + y\*y); temp.getAngle(a); temp.getRadius(r); return(temp); } \*/ int getLength(){return(length);} int getBredth(){return(bredth);} void putLength(float x){length = x;} void putBredth(float y){bredth = y;} void putData(){cout<<"Length : "<
as in the above code i have converted class Polar to class Rectangle, but i also want to have a conversion of class Rectangle to class Polar.
Thank you
Tarun Jha wrote:
as in the above code i have converted class Polar to class Rectangle,
Did you test it? Does it work? I ask because I see neither the assignment operator
Rectangle& Rectangle::operator =(const Polar& polar)
nor the ctor to create Rectangle instance from the Polar one... :confused:
-
i want to make a program that can convert from class a type to class b & vice versa.. i already made a program that does one type of conversion..
//define 2 classes polar & rectangle to represent points int the polar & rectanglular system.
#include
#include
using namespace std;class Polar;
//====================================================
class Rectangle{
float length, bredth;
public:
Rectangle(){}
Rectangle(float ,float);/\* operator Polar(){ Polar temp; float a = atan(length/bredth), r = sqrt(x\*x + y\*y); temp.getAngle(a); temp.getRadius(r); return(temp); } \*/ int getLength(){return(length);} int getBredth(){return(bredth);} void putLength(float x){length = x;} void putBredth(float y){bredth = y;} void putData(){cout<<"Length : "<
as in the above code i have converted class Polar to class Rectangle, but i also want to have a conversion of class Rectangle to class Polar.
Thank you
#include #include using namespace std;
class Polar;
//====================================================
class Rectangle
{
float length, bredth;
public:
Rectangle(){}
Rectangle(float ,float);operator Polar();
int getLength(){return(length);}
int getBredth(){return(bredth);}
void putLength(float x){length = x;}
void putBredth(float y){bredth = y;}void putData(){cout<<"Length : "<rectangle->polar
Polar p1(radians, 25);
p1.putData();Rectangle r1 = p1;
r1.putData();Polar p2 = r1;
p2.putData();return 0;
} -
#include #include using namespace std;
class Polar;
//====================================================
class Rectangle
{
float length, bredth;
public:
Rectangle(){}
Rectangle(float ,float);operator Polar();
int getLength(){return(length);}
int getBredth(){return(bredth);}
void putLength(float x){length = x;}
void putBredth(float y){bredth = y;}void putData(){cout<<"Length : "<rectangle->polar
Polar p1(radians, 25);
p1.putData();Rectangle r1 = p1;
r1.putData();Polar p2 = r1;
p2.putData();return 0;
} -
Tarun Jha wrote:
as in the above code i have converted class Polar to class Rectangle,
Did you test it? Does it work? I ask because I see neither the assignment operator
Rectangle& Rectangle::operator =(const Polar& polar)
nor the ctor to create Rectangle instance from the Polar one... :confused: