title: How can I do this with Smart Pointers?
body: <p>Here's what I'm trying to achieve:</p>
  
  <pre><code>#include &lt;iostream&gt;
  using std::cout;
  
  #include &lt;vector&gt;
  using std::vector;
  
  int main()
  {
      vector&lt;int&gt; a {3, 7};
  
      int *p = &amp;a.at (0); //assign 3
  
      for (int i = 0; i &lt; 10; ++i) //swap and print (3,7,3...)
      {
          p = (*p == a.at (0) ? &amp;a.at (1) : &amp;a.at (0));
          cout &lt;&lt; *p &lt;&lt; '\n';
      }
  }
  </code></pre>
  
  <p>I'd like to use smart pointers instead of raw pointers, seeing as how they are much better, but can't really figure out how to implement switching back and forth (this is to be used for taking turns in a game; It's a <code>Player *</code>).</p>
  
  <p>I tried replacing the pointers here with <code>std::unique_ptr</code> and <code>std::shared_ptr</code> in two separate tests, using <code>reset</code> to switch, with both giving random numbers after the first one, as expected.</p>
  
  <p>Next, I tried with <code>std::weak_ptr</code> as it looks like what I need, although the interface isn't really that similar. From what I've seen, the only way to use it is through <code>lock()</code>, so I tried prepending <code>lock().</code> to the calls of <code>reset</code> and appending it to dereferencing, but that crashed. </p>
  
  <p>How can I use <code>std::weak_ptr</code> instead of a raw pointer, or can I actually use one of the other ones somehow?</p>