home *** CD-ROM | disk | FTP | other *** search
- // Chap18_4.cpp
- #include <iostream.h>
- class Base
- {
- public:
- virtual void fn(int x)
- {
- cout << "In Base class, int x = " << x << "\n";
- }
- };
- class SubClass : public Base
- {
- public:
- virtual void fn(float x)
- {
- cout << "In SubClass, float x = " << x << "\n";
- }
- };
-
- void test(Base &b)
- {
- int i = 1;
- b.fn(i); //this call not bound late
- float f = 2.0F;
- b.fn(f); //neither is this one
- }
-
- int main()
- {
- Base bc;
- SubClass sc;
- cout << "Calling test(bc)\n";
- test(bc);
- cout << "Calling test(sc)\n";
- test(sc);
- return 0;
- }
-