home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-10-20 | 1023 b | 67 lines | [TEXT/CWIE] |
- #include <iostream.h>
- #include <string.h>
-
- const short kMaxNameLength = 40;
-
-
- //--------------------------------------- Name
-
- class Name
- {
- private:
- char first[ kMaxNameLength ];
- char last[ kMaxNameLength ];
-
- public:
- Name( char *lastName, char *firstName );
- void DisplayName();
- };
-
- Name::Name( char *lastName, char *firstName )
- {
- strcpy( last, lastName );
- strcpy( first, firstName );
- }
-
- void Name::DisplayName()
- {
- cout << "Name: " << first << " " << last;
- }
-
-
- //--------------------------------------- Politician
-
- class Politician
- {
- private:
- Name *namePtr;
- short age;
-
- public:
- Politician( Name *namePtr, short age );
- Name *operator->();
- };
-
- Politician::Politician( Name *namePtr, short age )
- {
- this->namePtr = namePtr;
- this->age = age;
- }
-
- Name *Politician::operator->()
- {
- return( namePtr );
- }
-
-
- //--------------------------------------- main()
-
- int main()
- {
- Name myName( "Clinton", "Bill" );
- Politician billClinton( &myName, 46 );
-
- billClinton->DisplayName();
-
- return 0;
- }