|
Boost : |
From: Noah Roberts (roberts.noah_at_[hidden])
Date: 2007-03-05 10:48:47
Manuel Fiorelli wrote:
> I thank you a lot for the suggestions and I want to say that:
>
> - I kept the original idea from Java Core Vol. 1 (by Cay Horstmann),
> where the author states that in C++ there aren't final classes, but they
> could be simulated through virtual inheritance....thus I tried to discovery
> that trick.
> - there is no reason to use a protected destructor; since I use
> private inheritance, automatic conversion of pointers from the derived class
> to the base class isn't possible, thus there is no reason to prevent
> accidental delete trough base class pointers...I realized it only after the
> submission...
> - unfortunately, I just discovered that the following code compiles
> (violating the "non derivable" semantics)
>
> struct Foo : BOOST_NON_DERIVABLE
> {
>
> };
>
> struct Goo : public Foo, BOOST_NON_DERIVABLE
> {
>
> };
>
> Foo foo; // a variant or a class member
> Goo goo;
But they have to purposefully violate the documented semantic use of the
class. This is good IMHO. You've told the user, "Don't try this," and
they're saying, "Well, I'm going to do it anyway." They know they
aren't supposed to...they're on their own. You can, and should, only do
so much semantic enforcement in C++.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk