From: Rob Stewart (stewart_at_[hidden])
Date: 2004-05-24 08:29:12
From: David Abrahams <dave_at_[hidden]>
> Rob Stewart <stewart_at_[hidden]> writes:
> > From: "Reece Dunn" <msclrhd_at_[hidden]>
> >> Q: Since the above is valid C++, is the following?:
> >> virtual void myfn( char ) = 0;
> >> virtual void myfn( int, bool ) = 0;
> > Absolutely. You can overload virtual functions just like
> > non-virtual functions.
> But unless they're all going to be overridden in one single class
> you're better off using the "template method pattern" and dispatching
> to differently-named functions to avoid problems with name
> hiding... or just be disciplined about bringing the base names into
> derived classes everywhere with "using".
Sure, but in the case leading to this query, they are const and
non-const versions of begin(), end(), rbegin(), and rend(). The
only opportunity for reuse of an underlying, common
implementation function, that I see is for the const overloads to
call the non-const overload.
The question is whether that is wise. Since the derived class
would implement the non-const version, there's no telling whether
it would try to modify the state of the object, so casting away
const-ness in order to call that overload from the const overload
could lead to undefined behavior.
As I see it, the derived class will have to implement all eight
of those functions, so they'll have to be pure virtual in the
-- Rob Stewart stewart_at_[hidden] Software Engineer http://www.sig.com Susquehanna International Group, LLP using std::disclaimer;
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk