previous | start | next

Writing a toString() Method: 7

If operator<< is not declared a friend in the Pair class, then in the Pair.h file, it should be declared outside the Pair class:

    1   class Pair
    2   {
    3     int x;
    4     int y;
    5   public:
    6     Pair() : x(0), y(0)
    7       { }
    8   
    9     Pair(int x, int y) : x(x), y(y)
   10     { }
   11   
   12     int getX() const;
   13     int getY() const;
   14     string toString() const;
   15   
   16   
   17   };
   18
   19   ostream& operator<<(ostream& os, const Pair& pr);


previous | start | next