previous | start | next

Overloading operator* for Pairs: 3

We actually need two operator* functions, one for each order of the two operands of *:

class Pair
{
  int x;
  int y;
public:
  Pair();
  Pair(int x, int y);
  int getX() const;
  int getY() const;
  string toString() const;

  Pair operator+(const Pair& b) const;
  friend Pair operator*(int a, const Pair& p);
  friend Pair operator*(const Pair& p, int a);
  friend ostream& operator<<(ostream& os, const Pair& pr);
};
        
     


previous | start | next