-
August 18th, 2018, 11:14 PM
#1
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
-
August 19th, 2018, 12:25 AM
#2
Re: Returning a vector of "objects" or floats out of a function
Originally Posted by luckiejacky
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|