Boost logo

Boost :

From: Dirk Gregorius (dirk_at_[hidden])
Date: 2004-12-18 15:10:00


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 inheriting from boost::noncopyable has the same effect:

// # 2
class Implementation : public Interface, /*public or private*/
boost::noncopyable
{
 public:
    void f() { /* Implementation */ }
    void g() { /* Implementation */ }
}

1.) Are #1 and #2 equivalent?
2.) When should I derive public and when private from boost::noncopyable?
3.) Is the use of noncopyable correct in this context and what are other
scenarios when to use it?

Regards,

-Dirk


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