home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / qt3_emx.zip / examples / qtl / qvaluelistiterator.cpp < prev   
C/C++ Source or Header  |  2001-10-11  |  1KB  |  55 lines

  1. /****************************************************************************
  2. ** $Id:  qt/qvaluelistiterator.cpp   3.0.0   edited Jun 1 18:44 $
  3. **
  4. ** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.
  5. **
  6. ** This file is part of an example program for Qt.  This example
  7. ** program may be used, distributed and modified without limitation.
  8. **
  9. *****************************************************************************/
  10.  
  11. #include <qvaluelist.h>
  12. #include <qstring.h>
  13. #include <qwindowdefs.h>
  14. #include <stdio.h>
  15.  
  16.  
  17. class Employee
  18. {
  19. public:
  20.     Employee(): s(0) {}
  21.     Employee( const QString& name, int salary )
  22.     : n(name), s(salary) {}
  23.  
  24.     QString name() const { return n; }
  25.  
  26.     int salary() const { return s; }
  27.     void setSalary( int salary ) { s = salary; }
  28. private:
  29.     QString n;
  30.     int s;
  31. };
  32.  
  33.  
  34. int main( int, char** )
  35. {
  36.     typedef QValueList<Employee> EmployeeList;
  37.     EmployeeList list;
  38.  
  39.     list.append( Employee("Bill", 50000) );
  40.     list.append( Employee("Steve",80000) );
  41.     list.append( Employee("Ron",  60000) );
  42.  
  43.     Employee joe( "Joe", 50000 );
  44.     list.append( joe );
  45.     joe.setSalary( 4000 );
  46.     
  47.     EmployeeList::ConstIterator it = list.begin();
  48.     while( it != list.end() ) {
  49.     printf( "%s earns %d\n", (*it).name().latin1(), (*it).salary() );
  50.     ++it;
  51.     }
  52.  
  53.     return 0;
  54. }
  55.