Boost logo

Boost :

From: Tom Widmer (tom_usenet_at_[hidden])
Date: 2005-01-13 10:53:30


Jonathan Wakely wrote:
> On Thu, Jan 13, 2005 at 12:49:33PM +1000, kalin wrote:
>
>
>>Hi All, I've made a simple implementation of making a class non-derivable.
>
>
> I can't compile this with GCC3 or Comeau.
> GCC2 lets me compile it (due to its flakey friend implementation) but it
> also allows Bar to inherit from Foo!
>
> This is a simpler way of preventing inheritance:
>
> class Finaliser
> {
> protected:
> Finaliser(){}
> };
>
> class Final : private virtual Finaliser
> {
> // rest of class as normal
> };

How about:

class Finaliser
{
   friend class Final;
   Finaliser(){}
};

class Final : private virtual Finaliser
{
};

?

Tom


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