home *** CD-ROM | disk | FTP | other *** search
- // ABSTRACT.CPP
- /*
-
- C++ program that illustrates the following
- small class hierarchy:
-
- AbstractArray
- |
- |
- /-----------------\
- | |
- | |
- | |
- | |
- | |
- OneChar ArrChar
-
- */
-
- #include <iostream.h>
-
- const int ARRAY_SIZE = 100;
-
- enum boolean { bFalse, bTrue };
-
- class AbstractChar
- {
- public:
- // pure-virtual functions (thus, this is an abstract class)
- virtual void store(unsigned char aCharacter) = 0;
- virtual unsigned char recall() = 0;
-
- // non-virtual member functions
- void nextChar();
- void prevChar();
- void show(const char* pMessage = "",
- boolean bNewLine = bTrue);
- };
-
- class OneChar : public AbstractChar // concrete class that
- // inherits from
- // AbstractChar class
- {
- public:
- // concrete implementations of pure-virtual functions
- virtual void store(unsigned char aCharacter)
- { aCharField = aCharacter; }
- virtual unsigned char recall()
- { return aCharField; }
-
- protected:
- unsigned char aCharField;
- };
-
- class ArrChar : public AbstractChar // concrete class that
- // inherits from
- // AbstractChar class
- {
- public:
- ArrChar(const unsigned IndexValue = 0)
- { theIndexValue = (IndexValue < ARRAY_SIZE) ?
- IndexValue : 0; }
- virtual void store(unsigned char aCharacter)
- { characterArray[theIndexValue] = aCharacter; }
- virtual unsigned char recall()
- { return characterArray[theIndexValue]; }
- void setIndex(const unsigned IndexValue = 0)
- { theIndexValue = (IndexValue < ARRAY_SIZE) ?
- IndexValue : 0; }
-
- protected:
- unsigned char characterArray[ARRAY_SIZE];
- unsigned theIndexValue;
- };
-
-
-