home *** CD-ROM | disk | FTP | other *** search
- // \EXAMPLES\EX1404.CPP
-
- #include <iostream.h>
- //--------------------------------------------------------------
- class base1 {
- public:
- virtual void f(int i)
- { cout << "int value is: " << i << endl; }
- };
-
- //--------------------------------------------------------------
- class derived1 : public base1 {
- public:
- void f(float f) // overrides base1 definition
- { cout << "float value is: " << f << endl; }
- // int f(int i) { } // error - return type doesn't match
- };
-
- //--------------------------------------------------------------
- void main() {
- derived1 d;
- base1* bp = &d;
- d.f(3.0); // calls derived1 definition of f()
- d.f(2); // calls derived1 definition of f()
- bp->f(3.0); // calls base1 definition of f()
- bp->f(2); // calls base1 definition of f()
- }
-
-
-
-