passing smart pointer to a function taking reference to a pointer parameter

c++, smart-pointers

Solution

The simple answer is that you can't. While the smart pointer almost certainly contains a `T*` somewhere internally, smart pointers enforce all sorts of invariants, many of which could be broken if you could change this pointer without passing through the user interface. The only solution is to call the function with a raw pointer, and then use the raw pointer to initialize the smart pointer, provided that you're sure that the pointer you get meets the requirements of the smart pointer (e.g. allocated by the `new` operator).

Problem

How can I pass smart ptr to a function taking reference to a pointer as a parameter? ``` smart_ptr<T> val; // I have this smart pointer // And I want to pass it to this function, so that this function will fill the smart pointer with proper value void Foo(T*& sth) { sth = memoryAddress; } ``` EDIT Now I get it. Thanks guys for all the answers!

Original source