C++的重载问题
#include<iostream>#include<math.h>classPCoor;classRCoor{private:doublex,y;public:doub...
#include <iostream>
#include <math.h>
class PCoor;
class RCoor
{
private:
double x,y;
public:
double GetX();
double GetY();
RCoor();
RCoor(double, double);
//重载赋值运算符 使之完成坐标转换
const RCoor &operator=(const PCoor&);
};
double RCoor::GetX()
{
return x;
}
double RCoor::GetY()
{
return y;
}
RCoor::RCoor()
{
x = 0.0;
y = 0.0;
}
RCoor::RCoor(double x, double y)
{
this->x = x;
this->y = y;
}
const RCoor& RCoor::operator=(const PCoor& pcoor)
{
double a = pcoor.GetAngle();
double r = pcoor.GetDis();
x = r * cos(a);
y = r * sin(a);
}
////////////////////////////////////////////////////////////////////////////////
class PCoor
{
private:
double angle, dis;
public:
double GetAngle();
double GetDis();
PCoor();
PCoor(double, double);
//重载赋值运算符 使之完成坐标转换
const PCoor& operator=( RCoor&);
};
double PCoor::GetAngle()
{
return angle;
}
double PCoor::GetDis()
{
return dis;
}
PCoor::PCoor()
{
angle = 0.0;
dis = 0.0;
}
PCoor::PCoor(double angle, double dis)
{
this->angle = angle;
this->dis = dis;
}
const PCoor& PCoor::operator=( RCoor& rcoor)
{
double x = rcoor.GetX();
double y = rcoor.GetY();
dis = sqrt(x*x + y*y);
angle = atan(y/x);
}
////////////////////////////////////////////////////////////////////////////////
int main()
{
return 0;
}
各位帮忙看一下。。这个应该怎么改啊。。?
error(43): invalid use of undefined type `const struct PCoor'
error(4): forward declaration of `const struct PCoor'
error(43):invalid use of undefined type `const struct PCoor'
error(4): forward declaration of `const struct PCoor' 展开
#include <math.h>
class PCoor;
class RCoor
{
private:
double x,y;
public:
double GetX();
double GetY();
RCoor();
RCoor(double, double);
//重载赋值运算符 使之完成坐标转换
const RCoor &operator=(const PCoor&);
};
double RCoor::GetX()
{
return x;
}
double RCoor::GetY()
{
return y;
}
RCoor::RCoor()
{
x = 0.0;
y = 0.0;
}
RCoor::RCoor(double x, double y)
{
this->x = x;
this->y = y;
}
const RCoor& RCoor::operator=(const PCoor& pcoor)
{
double a = pcoor.GetAngle();
double r = pcoor.GetDis();
x = r * cos(a);
y = r * sin(a);
}
////////////////////////////////////////////////////////////////////////////////
class PCoor
{
private:
double angle, dis;
public:
double GetAngle();
double GetDis();
PCoor();
PCoor(double, double);
//重载赋值运算符 使之完成坐标转换
const PCoor& operator=( RCoor&);
};
double PCoor::GetAngle()
{
return angle;
}
double PCoor::GetDis()
{
return dis;
}
PCoor::PCoor()
{
angle = 0.0;
dis = 0.0;
}
PCoor::PCoor(double angle, double dis)
{
this->angle = angle;
this->dis = dis;
}
const PCoor& PCoor::operator=( RCoor& rcoor)
{
double x = rcoor.GetX();
double y = rcoor.GetY();
dis = sqrt(x*x + y*y);
angle = atan(y/x);
}
////////////////////////////////////////////////////////////////////////////////
int main()
{
return 0;
}
各位帮忙看一下。。这个应该怎么改啊。。?
error(43): invalid use of undefined type `const struct PCoor'
error(4): forward declaration of `const struct PCoor'
error(43):invalid use of undefined type `const struct PCoor'
error(4): forward declaration of `const struct PCoor' 展开
展开全部
修改后的,代码里给了注释
#include <iostream>
#include <math.h>
class PCoor;
class RCoor
{
private:
double x,y;
public:
double GetX();
double GetY();
RCoor();
RCoor(double, double);
//重载赋值运算符 使之完成坐标转换
const RCoor &operator=(const PCoor&);
};
class PCoor //class声明移到前面
{
private:
double angle, dis;
public:
double GetAngle() const; //这里加const
double GetDis() const; //这里加const
PCoor();
PCoor(double, double);
//重载赋值运算符 使之完成坐标转换
const PCoor& operator=( RCoor&);
};
double RCoor::GetX()
{
return x;
}
double RCoor::GetY()
{
return y;
}
RCoor::RCoor()
{
x = 0.0;
y = 0.0;
}
RCoor::RCoor(double x, double y)
{
this->x = x;
this->y = y;
}
const RCoor& RCoor::operator=(const PCoor& pcoor)
{
double a = pcoor.GetAngle();
double r = pcoor.GetDis();
x = r * cos(a);
y = r * sin(a);
}
////////////////////////////////////////////////////////////////////////////////
double PCoor::GetAngle() const
{
return angle;
}
double PCoor::GetDis() const
{
return dis;
}
PCoor::PCoor()
{
angle = 0.0;
dis = 0.0;
}
PCoor::PCoor(double angle, double dis)
{
this->angle = angle;
this->dis = dis;
}
const PCoor& PCoor::operator=( RCoor& rcoor)
{
double x = rcoor.GetX();
double y = rcoor.GetY();
dis = sqrt(x*x + y*y);
angle = atan(y/x);
}
////////////////////////////////////////////////////////////////////////////////
int main()
{
return 0;
}
#include <iostream>
#include <math.h>
class PCoor;
class RCoor
{
private:
double x,y;
public:
double GetX();
double GetY();
RCoor();
RCoor(double, double);
//重载赋值运算符 使之完成坐标转换
const RCoor &operator=(const PCoor&);
};
class PCoor //class声明移到前面
{
private:
double angle, dis;
public:
double GetAngle() const; //这里加const
double GetDis() const; //这里加const
PCoor();
PCoor(double, double);
//重载赋值运算符 使之完成坐标转换
const PCoor& operator=( RCoor&);
};
double RCoor::GetX()
{
return x;
}
double RCoor::GetY()
{
return y;
}
RCoor::RCoor()
{
x = 0.0;
y = 0.0;
}
RCoor::RCoor(double x, double y)
{
this->x = x;
this->y = y;
}
const RCoor& RCoor::operator=(const PCoor& pcoor)
{
double a = pcoor.GetAngle();
double r = pcoor.GetDis();
x = r * cos(a);
y = r * sin(a);
}
////////////////////////////////////////////////////////////////////////////////
double PCoor::GetAngle() const
{
return angle;
}
double PCoor::GetDis() const
{
return dis;
}
PCoor::PCoor()
{
angle = 0.0;
dis = 0.0;
}
PCoor::PCoor(double angle, double dis)
{
this->angle = angle;
this->dis = dis;
}
const PCoor& PCoor::operator=( RCoor& rcoor)
{
double x = rcoor.GetX();
double y = rcoor.GetY();
dis = sqrt(x*x + y*y);
angle = atan(y/x);
}
////////////////////////////////////////////////////////////////////////////////
int main()
{
return 0;
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询