|
Boost : |
From: Maxim Yegorushkin (e-maxim_at_[hidden])
Date: 2004-12-19 06:53:34
Dirk Gregorius wrote:
> Does inheriting from boost::noncopyable has the same effect like making
> the copy c'tor and the assignment operator private without implementing
> them? The authors of the smart_ptr library suggest the following for the
> use of the smart pointers with interfaces:
>
> class Interface
> {
> public:
> virtual void f() = 0;
> virtual void g() = 0;
>
> protected:
> ~Interface( void ) {}; // non-virtual
> }
>
> // #1
> class Implementation : public Interface
> {
> public:
> void f() { /* Implementation */ }
> void g() { /* Implementation */ }
>
> private:
> // Not to be implemented
> Implementation( const Implementation& );
> Implementation& operator=( const Implementation& );
> };
Does it really make any sense making only implementation noncopyable,
rather than interface? If you deal with interfaces only it won't save you
from errors like this:
std::auto_ptr<Interface> create() { return
std::auto_ptr<Interface>(new Implementation); }
void foo()
{
std::auto_ptr<Interface> a(create()), b(create());
*a = *b; // oops, no error here, Implementation::operator= is not
considered
}
-- Maxim Yegorushkin
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk