February 2005
Beginner to intermediate
272 pages
4h 53m
English
In C++, an object can have multiple, valid addresses, and pointer comparison is not a question about addresses. It’s a question about object identity.
class Shape { ... };class Subject { ... };class ObservedBlob : public Shape, public Subject { ... };
In this hierarchy, ObservedBlob is derived from both Shape and Subject, and (because the derivation is public) there are predefined conversions from an ObservedBlob to either of its base classes.
ObservedBlob *ob = new ObservedBlob;Shape *s = ob; // predefined conversionSubject *subj = ob; // predefined conversion
The availability of these conversions means that a pointer to an ObservedBlob may be compared to a pointer to either of its base classes.
if( ob ...
Read now
Unlock full access