|
|
Warp wrote:
> By far the easiest (and most common) solution is to simply forbid
> copying
> and assignment of your class. This happens by declaring the copy
> constructor and assignment operator in the private part of the class and
> not implementing them. Problem solved. Of course now you can't copy nor
> assign instances of your class (nor can you use them in STL containers),
> but in many cases you don't need to. This is very typical for classes
> which you instantiate only once during the execution of the program.
>
> What forbidding those functionalities does is prevent accidents, so it's
> a good custom, even if you are not intending to copy/assign the class
> around.
>
> Sometimes you do want to copy/assign instances of your class, though.
> In that case you have to decide whether the copies should share the data
> or deep-copy it. If deep-copying is enough, then by far the easiest
> solution is replacing your array with a std::vector, and consequently you
> don't need to write any copy constructor / assignment operator. If you
> want to share, then you could use the smart pointers offered by the Boost
> library. (The current C++ standard doesn't yet offer such smart pointers,
> except for auto_ptr, which cannot be used for sharing data.)
More info on this is available on Warp's website :)
http://warp.povusers.org/c++test/
Post a reply to this message
|
|