c++关于坐标的计算

img


声明 Point 类,有坐标 _ x,_ y 两个成员变量;对Point 类重载“++”(自增)、“--”(自减)运算符,实现对坐标值的改变。求绿色区域内容。

// 前置++
Point& Point::operator++() {
    ++_x;
    ++_y;
    return *this;
}

// 后置++
Point Point::operator++(int) {
    Point tmp = *this;
    ++(*this);
    return tmp;
}

// 前置--
Point& Point::operator--() {
    --_x;
    --_y;
    return *this;
}

// 后置--
Point Point::operator--(int) {
    Point tmp = *this;
    --(*this);
    return tmp;
}

不知道你这个问题是否已经解决, 如果还没有解决的话:

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^