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

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