dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Returning a vector of "objects" or floats out of a function

  1. #1
    Join Date
    Dec 2010
    Posts
    114

    Returning a vector of "objects" or floats out of a function

    The third-user library, inside of the c file, when I include the vector header, it just doesn't compile because of certain conflict. But I indeed want to retrieve a set of values out of that function, if I use raw pointers, I am not sure when I will forget to clean up and leading to memory leaks, I don't want to save the data off the disk first and read it back.
    What is the way to do it?
    thanks
    Jack

  2. #2
    Join Date
    Feb 2017
    Posts
    374

    Re: Returning a vector of "objects" or floats out of a function

    Quote Originally Posted by luckiejacky View Post
    What is the way to do it?
    Firstly I would figure out what conflicts make it impossible to include <vector> and then fix that.

    Secondly I would assign each of the raw pointers to an std::shared_ptr before storing them in the vector.

    Then I can return the vector from the function not having to worry about the pointers. They will be automatically deleted when they go out of scope.
    Last edited by wolle; August 19th, 2018 at 04:35 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)