title: C++ objects and threads
body: <p>I am doing a simple server apllication, where you can have multiple connections, each connection is a single thread. This is the example I would like it to look like(it doesn't work), there is a collection of threads where each thread instantiates an object of the class connection:</p>
  
  <pre><code>class connection{};
  
  class server{
  std::vector&lt;std::thread&gt; active_connections;
  public:
      void listen() {active_connections.push_back(std::thread(connection));}
  };
  </code></pre>
  
  <p>I have been searching for the solution, but the best I could find were some member function threads. The solution turned quite wrong when I tested it, for example:</p>
  
  <pre><code>class connection{};
  
  class server{
  std::vector&lt;std::thread&gt; active_connections;
  public:
      void new_connection() { ... }
      void listen() { 
          active_connections.push_back(std::thread(&amp;server::new_connection,this)); }
      };
  </code></pre>
  
  <p>The message was: error: use of deleted function ‘std::thread::thread(const std::thread&amp;).
  Does that mean the std::thread class wants to copy the server class?? I don't know C++ that much so please don't flame, I'm only asking.</p>
  
  <p>Thanks!</p>
  
  <p>EDIT:</p>
  
  <p>This is where this happens:</p>
  
  <pre><code>void server::do_listen()
  {   
      int addr_size = sizeof(sockaddr_in);
      sockaddr_in client_sock;
      connection_info cn_info;
  
      while(true)
      {
          int csock;
          if((csock = accept(server_sock, (sockaddr*)&amp;client_sock, (socklen_t*)&amp;addr_size)) != -1)
          {
              printf("Incomming connection from %s.\n", inet_ntoa(client_sock.sin_addr));
              memset(&amp;cn_info,0, sizeof(connection_info));
              cn_info.sock_addr = client_sock;
              cn_info.sock = csock;
              std::thread thr(&amp;server::new_connection, *this, cn_info);
              thr.join();
          }
  
      }
  }
  </code></pre>
  
  <p>This is by far. The <code>server::new_connection()</code> is still empty.</p>