CArray
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: CArray

  1. #1
    Join Date
    Apr 2003
    Location
    kathmandu, nepal
    Posts
    1,570

    CArray

    In my MFC application in which I have a CArray Object defined like this;

    CArray<CCard, CCard&> m_CardArray; //this array contains the cards owned by a particular player

    The CCard objects are dynamically created in the heap throughout the program and added to the m_CardArray;

    .......
    .......

    CCard *pCard = new CCard;
    m_CardArray.Add(*pCard);
    .......
    .......

    Here pCard is a local pointer

    My problem is how to delete the CCard objects created on the heap like this so that no memory leak would be detected.

    Would using,

    m_CardArray.RemoveAll();

    OR

    m_CardArray.RemoveAt(...., .....);

    delete the the CCard objects created on the heap?

    Please Help me.

    Mitesh

  2. #2
    Join Date
    Aug 2000
    Location
    West Virginia
    Posts
    7,564
    You should be able to delete it right after the Add().
    You are storing CCard objects into the CArray, not
    pointers.

    In this case, I would just use a CCard veriable in the
    first place ...
    Code:
    CCard card;
    m_CardArray.Add(card);

  3. #3
    Join Date
    Apr 2003
    Location
    kathmandu, nepal
    Posts
    1,570
    Thanx a lot philip for opening my eyes. Now I realize how dumb I have been.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center