cv::Ptr assignment operator broken (Bug #3875)
Description
In OpenCV 2.4.x ,cv::Ptr<Type> a = new Type(something else);
was possible. The new cv::Ptr does not allow this. Maybe this functionality should be included for convenience and a little more backwards compatibility.
Associated revisions
Merge pull request #3875 from alalek:fix_build
History
Updated by Roman Donchenko over 10 years ago
First, you're not using the assignment operator in this example. Second, this change was done deliberately to discourage mixing raw and smart pointers.
And as far as convenience goes, I don't think using parentheses instead of an equals sign is any harder.
- Status changed from New to Cancelled
Updated by Philipp Hasper over 10 years ago
Thanks for the update and many thanks for your work on the smart pointer. Ok, it was not clear to me that mixing raw and smart pointers may be a problem.
Plus, it is not about "harder", its about migration issues.
cv::Ptr<Type> a;
...
a = new Type(...);
is also broken and something you cannot easily migrate to a.reset(new Type(...))
using regular expressions since you have to manually check that a is a cv::Ptr for every replacement. If that was bad coding style anyways and exactly the thing you want to prevent, please tell me so ;-).
Maybe it would be possible to just provide the operator=(T*
) which calls .reset()
internally.