From: Rob Stewart (stewart_at_[hidden])
Date: 2002-12-10 15:24:51
From: "Craig Henderson" <cdm.henderson_at_[hidden]>
> "Dirk Gerrits" <dirk_at_[hidden]> wrote in message
> > Craig Henderson wrote:
> > > I am deriving from boost::noncopyable to prevent copying of my
> > > objects. When I compile in VC7 with /W4 (warning level 4), I get a
> > > warning C4511 - copy constructor could not be generated
> > Isn't that what boost::noncopyable is supposed to do?
> In an ideal world, I wouldn't expect a warning or error unless I actually
> tried to copy the object.
> > > The documentation states that: "This warning can be caused by having a
> > > copy constructor for the base class that is not accessible by the
> > > derived class". As a result, I changed the copy ctor and assignment
> > > operator to be protected rather than private to make them visible to
> > > the derived class, and all is well.
> > Won't this mean that inside the class, copying will cause a link-time
> > failure, and outside of it a compile-time failure? The mistake of
> > accidentally copying an instance inside the class itself is probably
> > pretty rare, but still, catching errors as early as possible is
> > preferable IMHO.
Indeed. Making the copy ctor private means no class can invoke
the it other than boost::noncopyable, which is exactly right.
> I guess so, but I would prefer to take this minor disadvantage in return for
> a clean compile at warning level 4.
That's why VC supports pragmas to disable warnings.
VC is being overly verbose here. If you haven't tried copying
the class, then you should get no warning. If you try, you
should get errors; there's still no need for a warning.
-- Rob Stewart stewart_at_[hidden] Software Engineer http://www.sig.com Susquehanna International Group, LLP using std::disclaimer;
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk