previous | start | next

Overloading operator* for Pairs: 1

Suppose we want to multiply each element of Pair by an int:

        Pair p1(3,5);
        Pair p;

        p = 2 * p1;

or

        p = p1 * 2;

        // p should now be the pair x=6, y=10
     

The overloaded operator* will have one operand of type int and the other of type Pair.

Should this operator* be a member function or not?



previous | start | next