cv::Ptr
is a pointer-like type, which means it provides reference semantics. If you have a cv::Ptr
that is const
, it only gives you const
access to the object it is pointing at. This is actually a strange quirk, because normal pointers and the standard smart pointers do not work in this way. Your choice of function depends on whether you need to be able to modify the cv::FeatureDetector
.
If you need to modify it, your two choices are:
void foo(cv::Ptr<cv::FeatureDetector> detector) { /*...*/ }
void foo(cv::Ptr<cv::FeatureDetector>& detector) { /*...*/ }
The overhead of copying the cv::Ptr
is likely to be minimal (or at least have no effect on your program). I typically see any non-const
reference parameter as being an "output parameter", which suggests that the cv::Ptr
itself is going to modified. But due to the quirkiness of cv::Ptr
, what this really means is that it is allowing cv::FeatureDetector
to be modified. To avoid this confusion, I would much prefer the value parameter.
I assume you're using C++03 because you mentioned std::auto_ptr
, but if you ever upgrade to C++11 and if OpenCV adds a move constructor to cv::Ptr
, you'll also have the benefits of move semantics.
If you want to express that the cv::FeatureDetector
will not be modified, you can make the parameters const
. This ensures that you do not modify the cv::FeatureDetector
inside your function. Your choices are:
void foo(const cv::Ptr<cv::FeatureDetector> detector) { /*...*/ }
void foo(const cv::Ptr<cv::FeatureDetector>& detector) { /*...*/ }
This first one is really no different from the non-const
value parameter from the outside.