Passing const unique_ptr reference as parameter
问题 void f1(unique_ptr<A[]>& upA){ //some work... //callee can mess up smart pointer many ways for caller upA.reset(); //some work... } void f2(const unique_ptr<A[]>& upA){ //some work... //compiler stops callee from ruining smart pointer many ways for caller upA.reset(); //some work... } f1(upAArray); f2(upAArray); In the above code, calling f1 is dangerous because the callee can mess up the smart pointer by resetting it, releasing it, etc. Calling f2 is safe and everything works great. If