home *** CD-ROM | disk | FTP | other *** search
- // ex07005.cpp
- // Constructor conversion function
- #include <iostream.h>
- #include <time.h>
-
- class Date {
- int mo, da, yr;
- public:
- Date() {} // null constructor
- Date(time_t); // constructor conversion function
- void display(void);
- };
- // ----- member function to display the date
- void Date::display()
- {
- cout << mo << '/' << da << '/' << yr;
- }
- // ------ constructor conversion function
- Date::Date(time_t now)
- {
- struct tm *tim = localtime(&now);
- da = tim->tm_mday;
- mo = tim->tm_mon + 1;
- yr = tim->tm_year;
- }
-
- main()
- {
- time_t now = time((time_t *)NULL); // today's date and time
- Date dt(now); // invoke the conversion constructor
- dt.display(); // display today's date
- }