凌小帅000003
幼苗
共回答了20个问题采纳率:85% 举报
#include
#include
using namespace std;
class Point{
public:
explicit Point(int x = 0) : m_x(x), m_y(x) {}
Point(int x , int y) : m_x(x),m_y(y) {}
Point( const Pointrhs) : m_x(rhs.m_x),m_y(rhs.m_y) {}
~Point() {}
friend std::ostreamoperator<<( std::ostreamost, const Pointrhs)
{
ost << "( " << rhs.m_x << " , " << rhs.m_y << " )";
return ost;
}
friend std::istreamoperator>>( std::istreamist, Pointrhs)
{
ist >> rhs.m_x;
ist >> rhs.m_y;
return ist;
}
Pointoperator++()
{
++m_x;
++m_y;
return *this;
}
// for point++
const Point operator++(int)
{
Point tmp(m_x,m_y);
++m_x;
++m_y;
return tmp;
}
bool operator==(const Pointrhs)
{
return rhs.m_x == m_x rhs.m_y == m_y;
}
Pointoperator=( const Pointrhs )
{
m_x = rhs.m_x;
m_y = rhs.m_y;
return *this;
}
const Pointoperator+(const Pointrhs)
{
Point tmp;
tmp.m_x = m_x + rhs.m_x;
tmp.m_y = m_y + rhs.m_y;
return tmp;
}
friend Pointoperator+(int lhs, const Pointrhs)
{
Point tmp;
tmp.m_x = lhs + rhs.m_x;
tmp.m_y = lhs + rhs.m_y;
return tmp;
}
Pointoperator+=(const Pointrhs)
{
m_x += rhs.m_x;
m_y += rhs.m_y;
return *this;
}
void setX(int x)
{
m_x = x;
}
void setY(int y)
{
m_y = y;
}
void set(int x, int y)
{
m_x = x;
m_y = y;
}
private:
int m_x;
int m_y;
};
1年前
3