1

"I'm new to c++ and building a pong clone, and want to know what is and how to use overloading operators and why it is used?"

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;
    }
};

0 Answers0