A SERVICE OF

logo

P nSize. Y u can use the return value to check whether QueryP n actuallye o e
set the pen to the value you passed to it. This version of QueryP n checkse
the value of the parameter to make sure that it’ a legal value for the pens
size.
TLine also contains a definition for the == operator This operator checks to.
see if the two objects are actually the same object. If so, the operator returns
TRUE. Defining an array using the T rray class (which you’ll do later whenA
defining TLines) requires that the object used in T rray have the ==A
operator defined.
Lastly you should declare two operators,
<< and >>, to be friends of the
TLine class. When these operators are implemented later in this section,
they’ll provide easy access to stream operations for the SaveFile and
OpenFile functions.
Here is the declaration of the TLine class:
class TLine : public TPoints
{
public:
TLine(int penSize = 1) : TPoints(10, 0, 10) { PenSize = penSize; }
int QueryPen() const { return PenSize; }
int QueryPen(int penSize);
// The == operator must be defined for the container class,
// even if unused
BOOL operator ==(const TLine& other) const
{ return &other == this; }
friend ostream& operator <<(ostream& os, const TLine& line);
friend istream& operator >>(istream& is, TLine& line);
protected:
int PenSize;
};
Once you’ e defined the TLine class, you can define the TLines array andv
TLines array
the TLinesIterator array These containers work the same way as the TP ints. o
and TP intsIterator container classes that you defined earlier The onlyo .
difference is that, instead of containing an array of TP int objects likeo
TP ints, TLines contains an array of TLine objects.o
Here are the definitions of TLines and TLinesIterator:
typedef TArray<TLine> TLines;
typedef TArrayIterator<TLine> TLinesIterator;
Chapter 2, Learning ObjectWindows
61