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

  1. // \EXAMPLES\EX1404.CPP
  2.  
  3. #include <iostream.h>
  4. //--------------------------------------------------------------
  5. class base1 {
  6. public:
  7.   virtual void f(int i)
  8.     { cout << "int value is: " << i << endl; }
  9. };
  10.  
  11. //--------------------------------------------------------------
  12. class derived1 : public base1 {
  13. public:
  14.   void f(float f)            // overrides base1 definition
  15.     { cout << "float value is: " << f << endl; }
  16.   // int f(int i) { }        // error - return type doesn't match
  17. };
  18.  
  19. //--------------------------------------------------------------
  20. void main() {
  21.   derived1 d;
  22.   base1* bp = &d;
  23.   d.f(3.0);                  // calls derived1 definition of f()
  24.   d.f(2);                    // calls derived1 definition of f()
  25.   bp->f(3.0);                // calls base1 definition of f()
  26.   bp->f(2);                  // calls base1 definition of f()
  27. }
  28.  
  29.  
  30.  
  31.