Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 72009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T19:58:38+00:00 2026-05-10T19:58:38+00:00

std::auto_ptr is broken in VC++ 8 (which is what we use at work). My

  • 0

std::auto_ptr is broken in VC++ 8 (which is what we use at work). My main gripe with it is that it allows auto_ptr<T> x = new T();, which of course leads to horrible crashes, while being simple to do by mistake.

From an answer to another question here on stackoverflow:

Note that the implementation of std::auto_ptr in Visual Studio 2005 is horribly broken. http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=98871 http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=101842

I want to use

  • boost::scoped_ptr, for pointers that shouldn’t pass ownership.
  • boost::shared_ptr, for pointers in containers and elsewhere where they are required.
  • std::auto_ptr, for pointers that should/can pass ownership.

But since std::auto_ptr is broken for me, I wonder what would be the best approach:

  • Replace std::auto_ptr with something from the net. Like this this one from Rani Sharoni (haven’t tried it yet).
  • Use boost::shared_ptr instead. Will of course work, although there will be some minor overhead that I don’t care about. But I want to use auto_ptr to signal the intent of the pointer. (See this answer for a vote on this approach.)
  • I will never need to pass ownership in practice, so I shouldn’t worry about this.

Update: Here is what I did: I copied the aforementioned auto_ptr implementation by Rani Sharoni. From here.

Did some minor tests:

class T { public:     T() {         OutputDebugStringA('T\n');     };     ~T() {         OutputDebugStringA('~T\n');     }; };  {     fix::auto_ptr<T> x(new T); // This just works. } {     fix::auto_ptr<T> x = (new T); // Doesn't compile. Great! } {     fix::auto_ptr<T> x = fix::auto_ptr<T>(new T); // Transfer of ownership works also. } 

Of course these tests are by no means exhaustive and you shouldn’t trust them. Implementing an exception safe templated class is hairy business. At least this works better than the built in one.

Note: I don’t know if I’m allowed to use this implementation yet, with respect to copyright. I have emailed Rani and I’m waiting for a reply. I’ll update this post when I know more. Permission is granted for everyone to use Rani Sharoni’s auto_ptr implementation as you wish.

Thank you for all your replies.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T19:58:39+00:00Added an answer on May 10, 2026 at 7:58 pm

    Move to boost smart pointers.

    In the meantime, you may want to extract a working auto_ptr implementation from an old / another STL, so you have working code.

    I believe that auto_ptr semantics are fundamentally broken – it saves typing, but the interface actually is not simpler: you still have to track which instance is the current owner and make sure the owner leaves last.

    unique-ptr ‘fixes’ that, by making release not only give up ownership, but also setting the RHS to null. It is the closest replacement for auto-ptr, but with its different semantics it is not a drop-in replacement.

    There’s an introductory article to boost smart pointers, by, ahem, me.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 67k
  • Answers 67k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer I'm going to take a hard-nosed approach and say that… May 11, 2026 at 12:03 pm
  • added an answer Do you actually have 600 different rippers, or 600 streams… May 11, 2026 at 12:03 pm
  • added an answer If you are using XmlSerializer, you can add the XmlIncludeAttribute… May 11, 2026 at 12:03 pm

Related Questions

std::auto_ptr is broken in VC++ 8 (which is what we use at work). My
Why is it wrong to use std::auto_ptr<> with standard containers?
Seem to be having an issue with std::auto_ptr and assignment, such that the object
If I declare a temporary auto deleted character buffer using std::auto_ptr<char> buffer(new char[n]); then
std::next_permutation (and std::prev_permutation) permute all values in the range [first, last) given for a
For std::map, how will insert behave if it has to resize the container and
Is std::string size() a O(1) operation? The implementation of STL I'm using is the
If I have a std::vector or std::map variable, and I want to see the
What is std::pair for, why would I use it, and what benefits does boost::compressed_pair
For an std::map<std::string, std::string> variables , I'd like to do this: BOOST_CHECK_EQUAL(variables[a], b); The

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.