Boost logo

Boost :

From: Aleksey Gurtovoy (agurtovoy_at_[hidden])
Date: 2004-05-22 14:17:56


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

--
Aleksey Gurtovoy
MetaCommunications Engineering

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk