std::auto_ptr

This is a discussion on std::auto_ptr within the C++ Programming forums, part of the General Programming Boards category; Can someone please explain to me what this class does, and also how to use it?...

  1. #1
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718

    std::auto_ptr

    Can someone please explain to me what this class does, and also how to use it?
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    It's a smart pointer class that handles memory deallocation for you. For rudimentary pointer work, std::auto_ptr is sufficient, but if you want to do anything more useful (such as have containers of smart pointers) the boost library has a smarter smart pointer class. Stroustrup 14.4.2 (you do have it, right?) shows you how to use them.
    My best code is written with the delete key.

  3. #3
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    >> Stroustrup 14.4.2 (you do have it, right?)

    Nope. In fact, I own no programming books, but that's at the top of my list as soon as I get some money.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  4. #4
    Registered User
    Join Date
    May 2003
    Posts
    148

  5. #5
    Banned
    Join Date
    Jan 2003
    Posts
    1,708
    number five, page 2
    http://gamedev.net/reference/program...dcpp/page2.asp


    I just started looking into std::auto_ptrs (which I mentioned in that 3D vector class thread), and boost has many exceptionally good stuff
    www.boost.org

    EDIT: it makes me upset that there are people out there that look down upon using STL containers and classes. I've actually been criticized for using std::vectors in my own computer game engines because they think I am not l337 enough to write my own home grown containers. I think using stl containers is a good idea, especially for memory management and robustness.
    Last edited by Silvercord; 11-16-2003 at 01:17 PM.

  6. #6
    Cat
    Cat is offline
    Registered User
    Join Date
    May 2003
    Posts
    1,571
    Originally posted by Silvercord

    EDIT: it makes me upset that there are people out there that look down upon using STL containers and classes. I've actually been criticized for using std::vectors in my own computer game engines because they think I am not l337 enough to write my own home grown containers. I think using stl containers is a good idea, especially for memory management and robustness.
    If you get someone who truly says this is foolish, laugh in their face and leave. I think it's a good exercise to write one's own containers at least once, as a means of learning, but I would never be without the STL. It's effective, efficient, and safe.
    You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.

  7. #7
    Banned
    Join Date
    Jan 2003
    Posts
    1,708
    yeah, i've had to write all of that stuff for my C++ class last year in high school (im a senior now), and it's nice to be able to do that stuff, but stl has more work put into it.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21