title: curl problems in c++ class
body: <p>I read a few articles on c++ / curl here on stackoverflow and assembled the following. 
  The main goal is to handle the whole request in an instance of a class -- and maybe later in a secondary thread.</p>
  
  <p>My problem is: "content_" seems to stay empty though its the same addr and</p>
  
  <p>HttpFetch.h:</p>
  
  <pre><code>class HttpFetch
  {
  private:
      CURL *curl;
      static size_t handle(char * data, size_t size, size_t nmemb, void * p);
      size_t handle_impl(char * data, size_t size, size_t nmemb);
  public:
      std::string content_;
      static std::string url_;
      HttpFetch(std::string url);
      void start();
      std::string data();
  };
  </code></pre>
  
  <p>HttpFetch.cpp:</p>
  
  <pre><code>HttpFetch::HttpFetch(std::string url) {
  
      curl_global_init(CURL_GLOBAL_ALL); //pretty obvious
      curl = curl_easy_init();
  
      content_.append("Test");
      std::cout &lt;&lt; &amp;content_ &lt;&lt; "\n";
  
      curl_easy_setopt(curl, CURLOPT_URL, &amp;url);
      curl_easy_setopt(curl, CURLOPT_WRITEDATA, &amp;content_);
      curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &amp;HttpFetch::handle);
      //curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); //tell curl to output its progress
      curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
  
      //std::cout &lt;&lt; &amp;content_ &lt;&lt; "\n";
  }
  
  void HttpFetch::start() {
  
      curl_easy_perform(curl);
      curl_easy_cleanup(curl);
  }
  
  size_t HttpFetch::handle(char * data, size_t size, size_t nmemb, void * p)
  {
      std::string *stuff = reinterpret_cast&lt;std::string*&gt;(p);
  
      stuff-&gt;append(data, size * nmemb);
  
      std::cout &lt;&lt; stuff &lt;&lt; "\n"; // has content from data in it!
  
      return size * nmemb; 
  }
  </code></pre>
  
  <p>main.cpp:</p>
  
  <pre><code>#include "HttpFetch.h"
  int main(int argc, const char * argv[])
  {
  
      HttpFetch call = *new HttpFetch("http://www.example.com");
      call.start();
  
      ::std::cout &lt;&lt; call.content_ &lt;&lt; "\n"
  }
  </code></pre>
  
  <p>Thanks in advance</p>