Boost logo

Boost :

From: Rob Stewart (stewart_at_[hidden])
Date: 2004-05-24 08:30:23


From: "Aleksey Gurtovoy" <agurtovoy_at_[hidden]>
> David Abrahams 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...
>
> Yep, something like this:
>
> class base
> {
> public:
> void something() { do_something(); }
> void something(int n) { do_something(n); }
>
> private:
> virtual void do_something() = 0;
> virtual void do_something(int n) = 0;
> };
>
> class derived
> : public base
> {
> // both 'something' are still visible
>
> private:
> virtual void do_something(int n); // OK
> };

Sure, but you've both jumped off on a tangent unrelated to the
purpose of the original query. See my reply to Dave's message.

-- 
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