previous | start

Overloading operator* for Pairs: 4

The implementaions (in Pair.cpp).

Note: The Pair:: class scope operator is not used since these are not member functions of Pair:

Pair operator*(int a, const Pair& p)
{
  return Pair( a * p.getX(), a * p.getY() );
}

Pair operator*(const Pair& p, int a)
{
  return a * p;
}
     

The second version of operator* can be defined directly, but in this example it is defined in terms of the first version.



previous | start