Boost logo

Boost :

From: Dirk Gregorius (dirk_at_[hidden])
Date: 2004-12-19 07:43:36

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

I saw some code that declared the copy operations private in the base class.

class Interface
    virtual void f() = 0;

    Interface( const Interface& );
    Interface& operator=( const Interface& );

So in order to gain maximum style and correctness points I need to make both
classes ( Interface and Implementation ) noncopyable? Which means both need to
derive from boost::noncopyable?


Why is this possible? Does it make sense to dereference an interface?

Interface* p1 = make_interface();
Interface* p2 = make_interface();

*p1 = *p2;

Or does your example only work with auto/smart pointers?

Boost list run by bdawes at, gregod at, cpdaniel at, john at