home *** CD-ROM | disk | FTP | other *** search
- #include <stream.h>
-
- class C1 {
- int x;
- public:
- void foo (double x);
- void foo (int x);
- };
-
- class C2 : public C1 {
- public:
- void foo (long x);
- };
-
- void C1::foo (int x)
- {
- cout << "C1::foo(int)\n";
- }
-
- void C1::foo (double x)
- {
- cout << "C1::foo(double)\n";
- }
-
- void C2::foo (long x)
- {
- cout << "C2::foo()\n";
- }
-
- main()
- {
- C2 cl;
- C1 cl1;
- int i;
- long l;
- char c;
- double d;
-
- cl.foo (i);
- cl.foo (l); /* 2 */
- cl.foo (c);
- cl.foo (d); /* 3 */ //warning: double assigned to long
-
- cl1.foo (i);
- // cl1.foo (l); /* 6 */ //will not compile: bad argument list
- cl1.foo (c);
- cl1.foo (d);
-
- /* Guidelines C++
- All calls to c2.foo() call C2::foo(), even if it meant converting
- a double to a long. In (3), this was done even when the public
- base class had a foo(double) it could use. This contradicts my
- hypothesys. It seems instead that if a class contains a member function,
- then base class member functions of the same name are not inherrited.
-
- As an aside, notice that the compiler gave a warning when it found
- no function foo(double), but is casted it to a long and continues. But
- when it found no match for foo(long), it caused an error and did NOT
- continue. I would have expected it to use foo(double) and continue.
- */
-
- }
-