adding new object to vector, returns the same address every time
<p>I have the code:</p>

<p>My vector: <code>std::vector&lt;spreadsheet&gt; spreadsheets;</code></p>

<pre><code>//create a new spreadsheet if it doesn't already exist. Link the session to the spreadsheet.
bool server::createSpreadsheet(session* session, std::string name, std::string password)
{
    std::cout &lt;&lt; "beginning" &lt;&lt; std::endl;

    bool found = false;
    for(int i = 0; i &lt; spreadsheets.size(); i++)
    {

      spreadsheet test = spreadsheets.at(i);
      std::cout &lt;&lt; "spreadsheet name = " &lt;&lt; &amp;test &lt;&lt; std::endl;
      if(spreadsheets.at(i).name == name) //spread sheet already exists
      {
          found = true;

      }
    }
    std::cout &lt;&lt; "After For found = " &lt;&lt; found &lt;&lt; std::endl;

    if(!found) //create a spreadsheet
    {
      spreadsheet * spr = new spreadsheet(name, password);
      spr-&gt;linkSession(session);
      spreadsheets.push_back(*spr);
    }
    else
    {
      std::cout &lt;&lt; "in else" &lt;&lt; std::endl;
      return false;
    }
    return true;
}
</code></pre>

<p>I was hoping this would create a new spreadsheet object each time <code>found</code> was <code>false</code> and place it in the vector. But based on the output I am getting it seems it putting the same object every time? Im at a lost as to what is going on here?</p>

<p>Output after running it several times:</p>

<pre><code>beginning
spreadsheet name = 0x7fff568bce10
spreadsheet name = 0x7fff568bce10
spreadsheet name = 0x7fff568bce10
spreadsheet name = 0x7fff568bce10
spreadsheet name = 0x7fff568bce10
spreadsheet name = 0x7fff568bce10
spreadsheet name = 0x7fff568bce10
spreadsheet name = 0x7fff568bce10
spreadsheet name = 0x7fff568bce10
</code></pre>
