home *** CD-ROM | disk | FTP | other *** search
/ Microsoftware Monthly 19…2 Programming Power Tools / MASO9512.ISO / cpptutor / cpptutor.arj / EXAMPLES / EX0809.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-13  |  1.1 KB  |  43 lines

  1. // \EXAMPLES\EX0809.CPP
  2. // a class declared inside a function - a local class
  3. //-----------------------------------------------------------
  4.  
  5. #include <iostream.h>
  6. //------------------------------------------------------------
  7. // declaration of function containing a local class
  8. void action();
  9.  
  10. //-----------------------------------------------------------
  11. // main()
  12. void main()
  13. {  cout << "calling function action()" << endl;
  14.    action();
  15.    cout << "done" << endl;
  16. }
  17.  
  18. //----------------------------------------------------------
  19. // function action()
  20.  
  21. void action()
  22. {
  23.   static long time = 3600;
  24.   int i;
  25.   struct HMS {
  26.     int hour, min, sec;
  27.     //  member function of a local class     HMS::tick()
  28.     //     not allowed in Microsoft Virtual C++
  29.     //     for Virtual C, comment out next 4 lines
  30.   void tick ()
  31.   {  sec = time % 60;
  32.      //i++;                        // error
  33.      sec++;
  34.      /*...*/ }
  35.   };
  36.   HMS now;
  37.     //  member function of a local class     now.tick()
  38.     //     not allowed in Microsoft Virtual C++
  39.     //     for Virtual C, comment out next line
  40.   now.tick();
  41.   //...
  42. }
  43.