简体   繁体   中英

How to force cv::Mat to behave as a smart pointer

I'm designing c++/CLI library with many dll's and internal usage of opencv. OpenCV matrices are passed between theese dll and that is origin of my question:

Do you how to force cv::Mat to behave similar to std::unique_ptr, std::shared_ptr and std::weak_ptr?

A far as I know cv::Mat behave similar to std::shared_ptr (with reference counter), but what about other types of smart pointers?

By far the easiest method would be std::unique_ptr<cv::Mat> . It has the additional benefit of being obvious to future maintainers.

By itself this won't prevent others from holding on their own cv::Mat copy which would share ownership. You can partially prevent that: If ownership could be shared, clone the cv::Mat before putting it into the std::unique_ptr`. But anyone can later create additional cv::Mat's sharing ownership.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM