Re: Any compiler warning for default copy constructors?
Re: Any compiler warning for default copy constructors?
- Subject: Re: Any compiler warning for default copy constructors?
- From: Paul Walmsley <email@hidden>
- Date: Thu, 23 Feb 2006 12:31:57 +0000
Also worth getting into the habit of declaring a private copy
constructor and operator = for classes that are not designed to be
copied. This will cause a compile error for the sort of bug that bit
you!
I find boost's 'Non-Copyable' idiom very useful in this case -- either
include <boost/utility.hpp> (if you have boost installed already), or
roll your own:
class noncopyable
{
protected:
noncopyable(){}
~noncopyable(){}
private:
noncopyable( const noncopyable&);
const noncopyable& operator=( const noncopyable& );
};
Then if you have a class that you want to prevent being copied then
declare it like this:
class myclass : noncopyable // or boost::noncopyable
{
...
};
This has the great advantage as being a very visible indication that the
class isn't copyable -- certainly more so than declaring private
constructors.
Doesn't gcc also have a warning if you don't declare a copy constructor
but your class contains a pointer member? I'm sure I've seen that very
useful warning a few times.
Paul
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden