home *** CD-ROM | disk | FTP | other *** search
- // \EXAMPLES\EX0809.CPP
- // a class declared inside a function - a local class
- //-----------------------------------------------------------
-
- #include <iostream.h>
- //------------------------------------------------------------
- // declaration of function containing a local class
- void action();
-
- //-----------------------------------------------------------
- // main()
- void main()
- { cout << "calling function action()" << endl;
- action();
- cout << "done" << endl;
- }
-
- //----------------------------------------------------------
- // function action()
-
- void action()
- {
- static long time = 3600;
- int i;
- struct HMS {
- int hour, min, sec;
- // member function of a local class HMS::tick()
- // not allowed in Microsoft Virtual C++
- // for Virtual C, comment out next 4 lines
- void tick ()
- { sec = time % 60;
- //i++; // error
- sec++;
- /*...*/ }
- };
- HMS now;
- // member function of a local class now.tick()
- // not allowed in Microsoft Virtual C++
- // for Virtual C, comment out next line
- now.tick();
- //...
- }
-