Boost logo

Boost Users :

Subject: Re: [Boost-users] noncopyable
From: Hicham Mouline (hicham_at_[hidden])
Date: 2008-12-04 11:44:08


Like this?

class C : public boost::noncopyable {
public:
  ... clone() const
  {
   ...
  }
private:
   C( const C& rhs )
   {
     ....
   }
};

... instance c1 of C exists here ....

What possible return types of clone() const are possible?
.A native reference
.An auto_ptr

To be honest, I'm not sure myself of how it would be used...

Regards,

-----Original Message-----
From: boost-users-bounces_at_[hidden]
[mailto:boost-users-bounces_at_[hidden]] On Behalf Of Steven Watanabe
Sent: 04 December 2008 16:28
To: boost-users_at_[hidden]
Subject: Re: [Boost-users] noncopyable

AMDG

Hicham Mouline wrote:
> AFAIU, deriving from boost::noncopyable disables _accidental_ object
> copying.
>
> Is it possible to implement a clone() const member function of the object
> to _explicitly_ get a copy of the object?
>
> Perhaps deriving boost::noncopyable makes it totally impossible to ever
> get a copy of an object without resorting to byte copy.
>

boost::noncopyable has a private copy constructor and copy assignment
operator.
This prevents the compiler from generating a copy constructor and
assignment operator
for derived classes. That's all noncopyable does.

If you want a clone function, the easiest way is probably to implement a
private
copy constructor and have clone call it.

In Christ,
Steven Watanabe


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net