title: Understanding -Weffc++
body: <p>Consider the following program:</p>
  
  <pre><code>#include &lt;string&gt;
  
  struct S {
      S (){}
  
  private:
      void *ptr = nullptr;
      std::string str = "";
  };
  
  int main(){}
  </code></pre>
  
  <p>This, when compiled with <code>-Weffc++</code> on GCC 4.7.1, will spit out:</p>
  
  <pre>
  warning: 'struct S' has pointer data members [-Weffc++]
  warning:   but does not override 'S(const S&)' [-Weffc++]
  warning:   or 'operator=(const S&)' [-Weffc++]
  </pre>
  
  <p>That's no problem normally, except for a couple things with this example:</p>
  
  <ol>
  <li><p>If I comment out any of the constructor, the pointer declaration, or the string declaration, the warning disappears. This is odd because you'd think the pointer alone would be enough, but it isn't. Furthermore, changing the string declaration to an integer declaration causes it to disappear as well, so it only comes up when there's a string (or probably other choice classes) with it. Why does the warning disappear under these circumstances?</p></li>
  <li><p>Often times this warning comes up when all the pointer is doing is pointing to an existing variable (most often maintained by the OS). There's no <code>new</code>, and no <code>delete</code>. When the class with the handle, in these cases, is copied, I don't want a deep copy. I want both handles to point to the same internal object (like a window, for example). Is there any way to make the compiler realize this without unnecessarily overloading the copy constructor and assignment operator, or disabling the warning completely with <code>#pragma</code>? Why am I being bothered in the first place when the Rule of Three doesn't even apply?</p></li>
  </ol>