home *** CD-ROM | disk | FTP | other *** search
/ C++ for Dummies (3rd Edition) / C_FD.iso / CHAP18 / CHAP18_4.CPP < prev   
C/C++ Source or Header  |  1996-09-02  |  620b  |  38 lines

  1. // Chap18_4.cpp
  2. #include <iostream.h>
  3. class Base
  4. {
  5.   public:
  6.    virtual void fn(int x)
  7.    {
  8.       cout << "In Base class, int x = " << x << "\n";
  9.    }
  10. };
  11. class SubClass : public Base
  12. {
  13.   public:
  14.    virtual void fn(float x)
  15.    {
  16.       cout << "In SubClass, float x = " << x << "\n";
  17.    }
  18. };
  19.  
  20. void test(Base &b)
  21. {
  22.    int i = 1;
  23.    b.fn(i);        //this call not bound late
  24.    float f = 2.0F;
  25.    b.fn(f);        //neither is this one
  26. }
  27.  
  28. int main()
  29. {
  30.    Base bc;
  31.    SubClass sc;
  32.    cout << "Calling test(bc)\n";
  33.    test(bc);
  34.    cout << "Calling test(sc)\n";
  35.    test(sc);
  36.    return 0;
  37. }
  38.