title: How do you create objects that have an instance pointer of itself in a loop?
body: <p>I have the following class:</p>
  <pre><code>class Worker
  {
  private:
      const int m_id;
      Worker* m_partner = nullptr;
  public:
      Worker(const int &amp;id)
          :m_id(id){}
  
      Worker(const int &amp;id, Worker partner)
          :m_id(id)
      {
          m_partner = &amp;partner;
      }
  }
  </code></pre>
  <p>When I create a vector of workers like this:</p>
  <pre><code>std::vector&lt;Worker&gt; workers;
  workers.push_back(Worker(0, Worker(1)));
  workers.push_back(Worker(2, Worker(3)));
  workers.push_back(Worker(4, Worker(5)));
  </code></pre>
  <p>I get a good vector of worker-partner objects, with ids 0-1, 2-3 and 4-5. How can I create this in a for loop? When I try this:</p>
  <pre><code>for (int id = 0; id &lt; 6; id += 2)
  {
      workers.push_back(Worker(id, Worker(id+1)));
  }
  </code></pre>
  <p>all main workers are being partnered with partner 5, a.k.a. the last partner worker object created. Thanks in advance.</p>