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

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