Topic: overloading across derivation
Author: maxtal@physics.su.OZ.AU (John Max Skaller)
Date: Mon, 25 Jul 1994 15:09:33 GMT Raw View
>From: E.Frejaville@frcl.bull.fr (Etienne Frejaville)
>
>#include <iostream.h>
>class A {
> public :
> virtual int f() =0;
>};
>class B : public A {
> public :
> virtual int f(int n) {
> // Here we want to express f(int) with f() i.e
> // f(n) = n * f()
> // but we can't write : return n * f()
> // as f() is hidden by f(int). Neither A::f() can be used
> // as it would break virtuality and moreover it doesn't work
> // as f() is pure. The only way is to use a pointer to m.f :
> int (A::*pf)()=&A::f;
> return n * (this->*pf)();
> }
>};
Here's another method other than changing the name
of f(int):
class B : public A {
public:
using A::f;
virtual int f(int n) { return n * f(); }
};
This is a new facility of namespaces which permits
overloading of derived and base class methods.
(I think this is in the Working Draft at this time)
--
JOHN (MAX) SKALLER, INTERNET:maxtal@suphys.physics.su.oz.au
Maxtal Pty Ltd,
81A Glebe Point Rd, GLEBE Mem: SA IT/9/22,SC22/WG21
NSW 2037, AUSTRALIA Phone: 61-2-566-2189