How can I pass a std::unique_ptr
into a function? Lets say I have the following class:
class A
{
public:
A(int val)
{
_val = val
You're passing it by value, which implies making a copy. That wouldn't be very unique, would it?
You could move the value, but that implies passing ownership of the object and control of its lifetime to the function.
If the lifetime of the object is guaranteed to exist over the lifetime of the call to MyFunc, just pass a raw pointer via ptr.get()
.