“我是c ++的新手,正在构建pong克隆,想知道什么是,如何使用重载运算符以及为什么使用它?”
class Ball
{
private:
int x, y;
int originalX, originalY;
Dir direction;
public:
Ball(int posX, int posY)
{
originalX = posX;
originalY= posY;
x = posX; y = posY;
direction = STOP;
}
friend ostream& operator<<(ostream& o, Ball c)
{
o << "Ball [" << c.x << "," << c.y << "][" << c.direction << "]" << endl;
return o;
}
};