title: Running threads from within classes
body: <p>I'm trying to perform two operations at once, a loop in the program's main method that prints out <code>Tick from main</code> and another loop in a class that prints out <code>Tick from ConnectionManager</code>.</p>
  
  <p>This specific piece of code I'm running here is taken from one of the questions asked here.</p>
  
  <p><em>The main.cpp file:</em></p>
  
  <pre><code>#include &lt;Windows.h&gt; // printf, Sleep
  #include &lt;thread&gt; // thread
  
  // Include Connection Manager
  #include "ConnectionManager.h"
  
  int main() {
      ConnectionManager _CM;
  
      while (1) {
          printf("Tick from main");
          Sleep(1500);
      }
  }
  </code></pre>
  
  <p><em>ConnectionManager.h</em></p>
  
  <pre><code>#pragma once
  class ConnectionManager
  {
  private:
      void LoopForData();
  public:
      ConnectionManager();
  };
  </code></pre>
  
  <p><em>ConnectionManager.cpp</em></p>
  
  <pre><code>#include "ConnectionManager.h"
  
  #pragma once
  #include &lt;Windows.h&gt;
  #include &lt;thread&gt;
  
  void ConnectionManager::LoopForData() {
      while (1) {
          printf("Tick from connection manager\n");
          Sleep(1500);
      }
  }
  
  ConnectionManager::ConnectionManager()
  {
      std::thread tobj(&amp;ConnectionManager::LoopForData, this);
  }
  </code></pre>
  
  <p>The expected behaviour is that both loops run simultaneously, however the output I'm getting on the console is only from LoopForData function, and I get this error screen: <a href="https://imgur.com/a/WO5AKE8" rel="nofollow noreferrer">https://imgur.com/a/WO5AKE8</a></p>
  
  <p>What could I be missing?</p>