Open IanTheEngineer opened 8 years ago
There are a few cases of interest here. In both cases I suggest that we follow the google style guide for C++.
1) Reference arguments: google style guide: reference arguments
2) Object lifetime management: google style guide: smart pointers
3) Follow Resource Acquisition Is Initialization (RAII)
I agree with 2 and 3. However, on reading google's doc on reference arguments, I don't see a good justification for function outputs being passed by raw pointer. Who is responsible for cleaning up the object?
I believe that the caller is responsible for managing the object lifetime. This method of handling output arguments is also suggested by the ROS style guide.
If the function is creating an object with a non-trivial lifetime, then we should return a unique pointer to the object.
Right now pointers are both raw and shared. We should choose one (preferably shared) and stick with it. Additionally, we should consistently return shared pointers rather than passing them in by reference and populating them.