how to sort CAtlArray using qsort
This is nothing new at all,here is the source code:
CAtlArray< CSomeClass*> m_myArray; qsort(m_myArray.GetData(), m_myArray.GetCount(), sizeof(CSomeClass*), (int(*)(const void*, const void*))SortTheArray);
the Comparison function would look like the following:
int __cdecl SortTheArray(CSomeClass **pp1, CSomeClass **pp2)
{
....
}
Related posts:
Good point. But what if CAtlArray contains structs instead of pointers? I am using
struct MyFile { CString sFilename; LARGE_INTEGER Lcn; DWORD dwFragments; };
CAtlArray<MyFile> asFiles;
After sorting, the CStrings are messed up, and once the array is cleaned up there is an access violation.
thank you..
Yes It is works! Thank you very much!