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. CTypedPtrList

CTypedPtrList

Scheduled Pinned Locked Moved C / C++ / MFC
performancehelptutorialquestion
3 Posts 3 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.
  • Y Offline
    Y Offline
    yang__lee
    wrote on last edited by
    #1

    Hello, I have this variable in the Doc class. CTypedPtrList m_objectsList; Suppose at present it has 5 entries. I want to delete 3rd record. then how to achieve it? I tried. POSITION pos = m_objectsList.GetHeadPosition(); UINT cnt=0; while(pos!=NULL) { CObjData *objFmList = m_objectsList.GetNext(pos); cnt++; if(cnt==3) delete objFmList; } but then if next time I go to read this m_objectsList, program gives memory related error. How to do it safe way? thanks Leya

    N 1 Reply Last reply
    0
    • Y yang__lee

      Hello, I have this variable in the Doc class. CTypedPtrList m_objectsList; Suppose at present it has 5 entries. I want to delete 3rd record. then how to achieve it? I tried. POSITION pos = m_objectsList.GetHeadPosition(); UINT cnt=0; while(pos!=NULL) { CObjData *objFmList = m_objectsList.GetNext(pos); cnt++; if(cnt==3) delete objFmList; } but then if next time I go to read this m_objectsList, program gives memory related error. How to do it safe way? thanks Leya

      N Offline
      N Offline
      Nishad S
      wrote on last edited by
      #2

      You forgot to remove the item from the list. So at the next time you are deleting the object, which is previously deleted. - NS -

      P 1 Reply Last reply
      0
      • N Nishad S

        You forgot to remove the item from the list. So at the next time you are deleting the object, which is previously deleted. - NS -

        P Offline
        P Offline
        pathakr
        wrote on last edited by
        #3

        Thanks NS. pathak

        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