title: std::thread management: usage and best practice
body: <p>I'm trying to figure out threads after using them a bit in Java and I'm a bit baffled.
  Two questions:</p>
  
  <ul>
  <li>Can I extend my class from a thread or must I manage the thread from within the class via a handler?</li>
  <li>How do I save said thread handler? std::thread in and of itself does not appear to name a type.</li>
  </ul>
  
  <p>Any prod in the right direction would be greatly appreciated.</p>
  
  <p>How do I interpret this message?</p>
  
  <pre><code>src/CHandler.h:27:9: error: 'thread' in namespace 'std' does not name a type
           std::thread _thread;
           ^
  </code></pre>
  
  <p>And here's my attempt at extending thread:</p>
  
  <pre><code>src/CHandler.h:17:30: error: expected class-name before '{' token
   class CHandler : std::thread {
                                ^
  </code></pre>
  
  <p>Complete, troublesome header:</p>
  
  <pre><code>#ifndef __projectm__CHandler__
  #define __projectm__CHandler__
  
  #include &lt;set&gt;
  #include &lt;vector&gt;
  #include &lt;thread&gt;
  
  #include "CListener.h"
  
  class CHandler {
      public:
          virtual bool subscribe(std::shared_ptr&lt;CListener&gt; aListener);
          virtual bool unsubscribe(std::shared_ptr&lt;CListener&gt; aListener);
  
          virtual bool hasSubscriber(std::shared_ptr&lt;CListener&gt; aListener);
  
          virtual ~CHandler() {}
  
      protected:
          std::thread _thread;
          std::vector&lt;std::weak_ptr&lt;CListener&gt; &gt; _subscribers;
          std::set&lt;const CListener *&gt; _subscribersSet;
  
          virtual void run();
  };
  
  #endif /* defined(__projectm__CDefaultHandler__) */
  </code></pre>
  
  <p>Compiler version:</p>
  
  <pre><code>bash-3.1$ g++ --version
  g++.exe (GCC) 4.8.1
  </code></pre>
  
  <p>The makefile (a mess, I know - still learning this bloody thing):</p>
  
  <pre><code>CC=g++
  
  OUTFILE=game
  
  BINDIR=bin
  SRCDIR=src
  OBJDIR=obj
  
  CFLAGS=
  LDFLAGS=-std=c++0x
  
  
  
  all: core
  
  # Ядро проекта.
  core: $(OBJDIR)/main.o $(OBJDIR)/CGame.o $(OBJDIR)/CHandler.o $(OBJDIR)/CListener.o
      $(CC) $(CFLAGS) $(wildcard $(OBJDIR)/*.o) -o $(BINDIR)/$(OUTFILE)
  
  $(OBJDIR)/main.o: $(OBJDIR)
      $(CC) $(LDFLAGS) $(SRCDIR)/main.cpp -c -o $(OBJDIR)/main.o
  
  $(OBJDIR)/CGame.o: $(OBJDIR)
      $(CC) $(LDFLAGS) $(SRCDIR)/CGame.cpp -c -o $(OBJDIR)/CGame.o
  
  $(OBJDIR)/CHandler.o: $(OBJDIR)
      $(CC) $(LDFLAGS) $(SRCDIR)/CHandler.cpp -c -o $(OBJDIR)/CHandler.o
  
  $(OBJDIR)/CListener.o: $(OBJDIR)
      $(CC) $(LDFLAGS) $(SRCDIR)/CListener.cpp -c -o $(OBJDIR)/CListener.o
  
  # Создаем директорию для объектов, если ее нет.
  $(OBJDIR):
      mkdir $(OBJDIR)
  
  main.o: $(SRC)/main.cpp
  </code></pre>