Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. how to detele auto pointer?

how to detele auto pointer?

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestionannouncement
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    valerie99
    wrote on last edited by
    #1

    hi, all does anybody know when should be release the auto pointer? thanks! m_pdbf = std::auto_ptr( new CBNoMessageBox_DBF_NTX( pszFileName ) );

    J J 2 Replies Last reply
    0
    • V valerie99

      hi, all does anybody know when should be release the auto pointer? thanks! m_pdbf = std::auto_ptr( new CBNoMessageBox_DBF_NTX( pszFileName ) );

      J Offline
      J Offline
      Johann Gerell
      wrote on last edited by
      #2

      That's not the way to use a std::auto_ptr. Do like this:

      std::auto_ptr msgbox(new CBNoMessageBox_DBF_NTX(pszFileName));
      msgbox->SomeMemberFunctionOfCBNoMessageBox_DBF_NTX();

      valerie99 wrote: does anybody know when should be release the auto pointer? Normally - never, since the allocated memory is deleted by std::auto_ptr at scope exit. But if you must, then std::auto_ptr<>::release() is your friend. -- The Blog: Bits and Pieces -- modified at 18:10 Monday 26th September, 2005

      J 1 Reply Last reply
      0
      • V valerie99

        hi, all does anybody know when should be release the auto pointer? thanks! m_pdbf = std::auto_ptr( new CBNoMessageBox_DBF_NTX( pszFileName ) );

        J Offline
        J Offline
        Jorgen Sigvardsson
        wrote on last edited by
        #3

        The autopointer deletes its associated object when it goes out of scope automatically. To destroy it sooner, call reset(). -- Keep talking! You're the fool, I'm the preacher.

        1 Reply Last reply
        0
        • J Johann Gerell

          That's not the way to use a std::auto_ptr. Do like this:

          std::auto_ptr msgbox(new CBNoMessageBox_DBF_NTX(pszFileName));
          msgbox->SomeMemberFunctionOfCBNoMessageBox_DBF_NTX();

          valerie99 wrote: does anybody know when should be release the auto pointer? Normally - never, since the allocated memory is deleted by std::auto_ptr at scope exit. But if you must, then std::auto_ptr<>::release() is your friend. -- The Blog: Bits and Pieces -- modified at 18:10 Monday 26th September, 2005

          J Offline
          J Offline
          John M Drescher
          wrote on last edited by
          #4

          Johann Gerell wrote: That's not the way to use a std::auto_ptr There can be a good reason for this. Suppose the auto_ptr was declared as a class member and not initialized in the constructor of the class. I have done this from time to time. John

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups