News for hackers. Stuff that matters.
Re:My Most Important C++ Aha Moments (2006) by hendzen on Sunday June 26, 2016 @07:40AM (#11980387)
There is an obscure pitfall of making a class noncopyable by making the copy constructor private.

Consider the following class:

  class X { 
   private:
     X& (const X&); // not defined
   public:
     X bar() {
        X x = ......;
        return x;
     }
   };
Due to programmer error, an instance of X is returned by value despite the class being noncopyable. The copy constructor being private doesn't help as bar() is a method of X. This will compile and link, despite the copy constructor being undefined. I will leave the reason for this as an exercise for the reader.
Re:My Most Important C++ Aha Moments (2006) by gliptic on Sunday June 26, 2016 @08:48AM (#11980542)
It might compile, but it won't link.
Re:My Most Important C++ Aha Moments (2006) by nowne on Sunday June 26, 2016 @11:54AM (#11981286)
It will likely link, since both clang and gcc will perform RVO on bar(), so the copy constructor won't be called.