title: C++ thrift implementation as a class
body: <p>So I'm trying to convert the following C++ thrift server implementation most tutorials give into class form:</p>
  
  <pre><code>int port = 9090;
    shared_ptr&lt;SomethingHandler&gt; handler(new SomethingHandler());
    shared_ptr&lt;TProcessor&gt; processor(new SomethingProcessor(handler));
    shared_ptr&lt;TServerTransport&gt; serverTransport(new TServerSocket(port));
    shared_ptr&lt;TTransportFactory&gt; transportFactory(new TBufferedTransportFactory());
    shared_ptr&lt;TProtocolFactory&gt; protocolFactory(new TBinaryProtocolFactory());
  
    TSimpleServer server(processor, serverTransport, transportFactory, protocolFactory);
  </code></pre>
  
  <p>To do that I made all the shared_ptrs and TSimpleServer members, but I'm running into trouble with initilization assignment.</p>
  
  <p>constructing shared_ptr's in initlization lists seems to result in badmalloc errors, so my workaround was to declare them as members and initialize through asisgnment: </p>
  
  <pre><code> handler = shared_ptr&lt;type&gt;(new Type). 
  </code></pre>
  
  <p>The problem here is that TSimpleServer has no assignment operator or constructor taking void, so it needs the shared_ptrs it depends on constructed at constructor time so it can be constructed.<br>
  Any thoughts what I am missing here?</p>
  
  <p>More psuedocode:</p>
  
  <pre><code>class myclass {
   int port;
   shared_ptr&lt;MyHandlder&gt; handler;
   shared_ptr&lt;TProcessor&gt; processor;
   shared_ptr&lt;TServerTransport&gt; serverTransport;
   shared_ptr&lt;TTransportFactory&gt;  transportFactory;
   shared_ptr&lt;TProtocolFactory&gt; protocolFactory;
   TSimpleServer server;
  
    public: 
          explicit myclass(): port(9090), handler(new MyHandler()), processor(new MyProcessor(handler)), serverTransport(new TServerSocket(port)), transportFactory(new TBufferedTransportFactory()), protocolFactory(new TBinaryProtocolFactory()), server(processor, serverTransport, transportFactory, protocolFactory) { }
  
   int start () { server.serve() }
  </code></pre>