Link to home
Start Free TrialLog in
Avatar of jxbma
jxbmaFlag for United States of America

asked on

How do I iterate over a vector that is wrapped in a smart pointer in Microsoft C++ 11?

Hi:

I have a Microsoft C++ 11 application.

I have a vector of shared_ptrs that get returned from a method call.
In order for that vector not to be leaked, I have wrapped it in a shared_ptr as well.

How do I iterate over that vector when it is wrapped in a smart (shared) pointer?

// Definition of the method
shared_ptr<vector<shared_ptr<Foo>>> GetVectorOfValues(){}

// Now in another method....
{
   ...
   shared_ptr<vector<shared_ptr<Foo>>> values =  GetVectorOfValues();

   for (auto value : values.get())
   {
   }
}

Open in new window


I would have thought that "get()" would get me to the wrapped vector.
How would I go about doing this?

Is there a better pattern to use to achieve my goals?

Thanks,
JohnB
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jxbma

ASKER

Thank-you old school!