1

I have a shared pointer to the result of some calculation as follows:

std::list<std::shared_ptr<myResult>> ResultList;
for (int i= 0; i < upperBound; i++)
{
    DoCalculation();
    std::shared_ptr<myResult> Res;
    Res = DoCalculation->GetOutput();
    ResultList.push_back(Res);
}

In debug mode I can see that at each iteration Res is updated, though all values in ResultList are equal to the last iteration's Res pushed to ResultList. How can I keep the result of calculation in the list using Res?

QuestionMark
  • 412
  • 1
  • 4
  • 16
  • can you just do `ResultList.push_back(DoCalculation->GetOutput());` – Kevin Apr 12 '15 at 23:02
  • "all values in ResultList are equal to the last iteration's Res pushed to ResultList" - Do you mean that each value is equal to the value from the previous iteration or that all values are equal to the last single value? – Question Marks Apr 16 '15 at 18:52
  • If Res is properly being set, then the way you're pushing it into the list is correct. How are you checking the values in ResultList? – Question Marks Apr 16 '15 at 18:54

0 Answers0