home *** CD-ROM | disk | FTP | other *** search
- // ex06008.cpp
- // Returning a reference from a function
- #include <iostream.h>
- #include <stdlib.h>
-
- // ---------- a date structure
- struct date {
- int mo, da, yr;
- };
-
- // -------- an array of dates
- date birthdays[] = {
- {12, 17, 37},
- {10, 31, 38},
- { 6, 24, 40},
- {11, 23, 42},
- { 8, 5, 44},
- };
-
- // ----- a function to retrieve a date
- date& getdate(int n)
- {
- return birthdays[n-1];
- }
-
- main(int argc, char *argv[])
- {
- if (argc > 1) {
- date& bd = getdate(atoi(argv[1]));
- cout << bd.mo << '/' << bd.da << '/' << bd.yr;
- }
- }