Creating unique object pointers in a loop
<p>I need to create object pointers in a loop, but I am struggling with creating unique pointers. Here's my code:</p>

<pre><code>class DatClass{
  public:

  int m;

  DatClass(int i):m(i){}
};

class OtherClass{
  public:
  DatClass* dc;
};

void Test(std::vector&lt;OtherClass&gt; v){
  std::vector&lt;OtherClass&gt;::iterator it;
  int i = 1;
  for(it = v.begin(); it != v.end(); it++){
    DatClass dc = DatClass(i);
    std::cout &lt;&lt; &amp;dc &lt;&lt; std::endl;
    it-&gt;dc = &amp;dc;
    i++;
  }
}

int main(){
  std::vector&lt;OtherClass&gt; v;
  v.push_back(OtherClass());
  v.push_back(OtherClass());
  v.push_back(OtherClass());
  Test(v);
}
</code></pre>

<p>This does not give me unique pointers. The output reads:</p>

<pre><code>0xbf94d72c
0xbf94d72c
0xbf94d72c
</code></pre>

<p>Do I need to use new in order to get unique pointers? If so, where would I put the corresponding delete?
Thanks!</p>
