From: David Abrahams (dave_at_[hidden])
Date: 2004-12-18 20:10:59
Joaquin M Lopez Munoz wrote:
> Dirk Gregorius <dirk <at> dirkgregorius.de> writes:
>> 1.) Are #1 and #2 equivalent?
> In a broad sense, yes. The problem is that many compilers
> don't do EBO (empty base optiimzation) in the presence
> of multiple inheritance, which might end up (in #2)
> with sizeof(Implementation) being greater than strictly needed.
>> 2.) When should I derive public and when private from boost::noncopyable?
> Given what I said, I think that deriving from boost::noncpyable
> must be avoided if multiple inheritance is present and you
> expct your class to be allocated on the stack.
"Must be avoided" is a bit strong. One extra byte usually makes no
difference for a class that will be allocated on the stack. If you're
going to have hundreds of thousands of them in an application, then
maybe it's worth thinking about. And anyway, this limitation only
applies to some compilers. If the OP is targeting GCC 3.x, for example,
he doesn't need to worry about that EBO pessimization at all.
Anyway the OP asked about public vs. private. It doesn't really matter
which you use, though for maximum style points you should use private
inheritance with noncopyable.
> In all other
> cases, deriving from noncpyable is more expressive than
> the traditional idiom.
It's always more expressive. Sometimes there are good reasons to
sacrifice that expressivity to achieve something else.
-- Dave Abrahams Boost Consulting http://www.boost-consulting.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk