Click here to Skip to main content
15,845,469 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have:

<pre>CArray <CCheckMio*, CCheckMio*> m_aCheck;

m_button = new CCheckMio();

			bRes = m_button->Create(_T(""), WS_CHILD | WS_VISIBLE | BS_CHECKBOX, rect1, this, 1);

then I mnust delete elements of m_aCheck

for (int ij = 0; ij < m_listMia.m_aCheck.GetCount(); ij++)
		delete m_listMia.m_aCheck[ij];

but software crashes

What I have tried:

I tried code that I wrote, I don't know how I can delete elements that are inside array
Updated 2-Dec-22 5:40am

1 solution

You haven't provided any details of the error you're getting. But if you're going to delete elements from a collection as you're iterating over it, it's always a good idea to iterate backwards so that you don't end up skipping items or going past the end of the collection.
for (int ij = m_listMia.m_aCheck.GetCount() - 1; ij >= 0; ij--)
        delete m_listMia.m_aCheck[ij];
Share this answer
Member 14594285 2-Dec-22 11:42am    
thanks I solved

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900