title: How to pass smart pointers in function?
body: <p>In the following example, when I pass <code>p</code> to a function, It gets destroyed as soon as the function func exits</p>
  <pre><code>void func(std::auto_ptr&lt;int&gt; p)
  {
     // deletes p
  }
  
  int main()
  {
      std::auto_ptr&lt;int&gt; p(new int);
      func(p);
      *p = 1; // run-time error
  }
  </code></pre>
  <p>I'm also told that passing smart pointers by reference is very bad design from the book &quot;The C++ Standard Library - Reference by Nicolai M. Josuttis&quot;.</p>
  <p>Quote:</p>
  <blockquote>
  <p>Allowing an auto_ptr to pass by reference is very bad design and you
  should always avoid it <strong>.....</strong></p>
  <p><strong>.....</strong>  According to the concept of auto_ptrs, it is possible to transfer ownership into a function by using a constant reference.</p>
  </blockquote>
  <p>Is it not possible to pass smart pointers or have I got the wrong idea?</p>