• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Any compiler warning for default copy constructors?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Any compiler warning for default copy constructors?
      • From: Howard Hinnant <email@hidden>
    • Re: Any compiler warning for default copy constructors?
      • From: "Clark Cox" <email@hidden>
References: 
 >Any compiler warning for default copy constructors? (From: Scott Fraser <email@hidden>)
 >Re: Any compiler warning for default copy constructors? (From: "Clark Cox" <email@hidden>)
 >Re: Any compiler warning for default copy constructors? (From: Steve Baxter <email@hidden>)

  • Prev by Date: Xcode 2.2 linker problem with 64-bit code and -O0 ?
  • Next by Date: Re: include problems with XCode and frameworks [solved]
  • Previous by thread: Re: Any compiler warning for default copy constructors?
  • Next by thread: Re: Any compiler warning for default copy constructors?
  • Index(es):
    • Date
    • Thread