运算符重operator的+ - *运算
classvector{intx;inty;public:vector(){x=0;y=0;}vector(inta,intb){x=a;y=b;}vectoropera...
class vector
{
int x;
int y;
public:
vector()
{
x=0;y=0;
}
vector(int a,int b)
{
x=a;y=b;
}
vector operator+(vector vec)
{
vector temp(0,0);
temp.x=x+vec.x;
temp.y=y+vec.y;
returm temp;
}
vector operator-(vector vec)
{
vector temp(0,0);
temp.x=x-vec.x;
temp.y=y-vec.y;
returm temp;
}
friend vector operator+(vector vec,float val)
void display()
{
cout<<"x"<<","<<y<<");
}
vector operator*(vector vec,float val)
{
vector temp(0,0);
temp.x=vec.x*val;
temp.y=vec.y*val;
returm temp;
}
这段代码什么意思 还有关于operator的+ - *运算格式和怎么实现 展开
{
int x;
int y;
public:
vector()
{
x=0;y=0;
}
vector(int a,int b)
{
x=a;y=b;
}
vector operator+(vector vec)
{
vector temp(0,0);
temp.x=x+vec.x;
temp.y=y+vec.y;
returm temp;
}
vector operator-(vector vec)
{
vector temp(0,0);
temp.x=x-vec.x;
temp.y=y-vec.y;
returm temp;
}
friend vector operator+(vector vec,float val)
void display()
{
cout<<"x"<<","<<y<<");
}
vector operator*(vector vec,float val)
{
vector temp(0,0);
temp.x=vec.x*val;
temp.y=vec.y*val;
returm temp;
}
这段代码什么意思 还有关于operator的+ - *运算格式和怎么实现 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询