简体   繁体   中英

Smart Pointers compatibility with raw pointers

I am using a library that uses raw pointers. In my code, I use smart pointers. How do I make them compatible. For example, I have an object

std::unique_ptr<Canvas> m_canvas;

But a function call in library is

f(..., Canvas* c,...);

How do I pass m_canvas to f ?

If the function doesn't take ownership, you might use get() :

f(m_canvas.get());

If the function takes ownership, you might use release() :

consume(m_canvas.release());

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