Tools.h++ Manual

20-2 104011 Tandem Computers Incorporated
20
For example:
The compiler will treat this definition of
isEqual()
as completely
independent of the
isEqual()
in the base class
RWCollectable
because it is
missing a "
const
" modifier. Hence, if called through a pointer:
20.2 Iterators
Immediately after construction, the position of a Tools.h++ iterator is formally
undefined. You must advance it or position it before it has a well-defined
position. The rule of thumb is "advance and then return". The return value
after advancing will be "special", either
FALSE
or nil, depending on the type of
iterator, if the end of the collection has been reached.
Hence, the proper idiom is:
class MyObject : public RWCollectable {
public:
RWBooleanisEqual();// No "const" !
};
MyObject obj;
RWCollectable* c = &obj;
c->isEqual();// RWCollectable::isEqual() will get called!
RWSlistCollectables ct;
RWSlistCollectablesIterator it(ct);
.
.
.
RWCollectable* c;
while (c=it()) {
// Use c
}