Re: Copy constructors
- From: "Doug Harrison [MVP]" <dsh@xxxxxxxx>
- Date: Sun, 08 Jul 2007 13:33:24 -0500
On Sun, 8 Jul 2007 09:24:45 +0100, "David Webber"
<dave@xxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
"Mateusz Loskot" <mloskot@xxxxxxxxx> wrote in message
news:op.tu3s98g1bk1lju@xxxxxxxxxxxxxxxxx
You've got already it well explained, so I'm only giving
yet another possible solution:
// http://www.boost.org
#include <boost/utility.hpp>
class A : boost::noncopyable
{
};
and you do not need to add any extra code to definition of A.
Thanks! One of these days I must explore the "boost" library, as I have
seen it recommended a few times.
But the simple trick of declaring, but not implementing, a copy constructor
appeals to me as a very simple procedure entirely within the C++ standard.
I have now used this to fix up my problems and it works fine.
I expect the boost::noncopyable class does the same thing, as the compiler
can't generate the defaults in derived classes if the base class versions
are inaccessible. It should even be slightly superior to what I presented,
since attempts by "A" and its friends to makes copies of "A" would be
diagnosed at compile-time instead of link-time. On the other hand, I
wouldn't want to use the boost method with a compiler that doesn't support
the empty base class optimization. All that said, the boost facility is
still cumbersome. Given that I make most of the classes I write
non-copyable, I wish the language would address this directly.
--
Doug Harrison
Visual C++ MVP
.
- Follow-Ups:
- Re: Copy constructors
- From: Mateusz Loskot
- Re: Copy constructors
- References:
- Copy constructors
- From: David Webber
- Re: Copy constructors
- From: Mateusz Loskot
- Re: Copy constructors
- From: David Webber
- Copy constructors
- Prev by Date: Re: memset32
- Next by Date: two monitors
- Previous by thread: Re: Copy constructors
- Next by thread: Re: Copy constructors
- Index(es):
Relevant Pages
|