title: Closing a connection in a destructor in C++
body: <p>I was thinking about a C++ class that manages my TCP connections (on Linux). Upon destruction the connection should be closed similar to this:</p>
  
  <pre><code>TCPConnection::~TCPConnection()
  {
    close(_socket);
  }
  </code></pre>
  
  <p>The problem is that when putting an object of this class into e.g. a vector the connection will also be closed like this even though I would still like to use the connection. How can I solve this? Is this a bad idea in general?</p>