jase jennings
February 27th, 2003, 05:37 PM
Hi
Is it possible to pass a reference of "this" ? I am extending the MFC CStringArray class. I need to reference the string array using the [] operator, but i cannot do this on a pointer, it needs to be on a reference to the original object. I don't have access to the actual member data (as far as i can tell from the docs)
Am i making this clear ? Here's a code snippet which will explain.
void SortStringArray (CStringArray &csa, BOOL bDescending)
{
int iArraySize = csa.GetSize();
if (iArraySize <= 0)
return;
int iCSSize = sizeof (CString*);
void* pArrayStart = (void *)&csa[0]; // i cannot do this on a pointer, so i cannot pass a "this" pointer to this func
if (bDescending)
qsort (pArrayStart, iArraySize, iCSSize, CompareDescending);
else
qsort (pArrayStart, iArraySize, iCSSize, CompareAscending);
}
void CSortStringArray::QuickSort(bool *pbCancel /* = false */)
{
SortStringArray(this, FALSE); // can't pass "this". Need to pass a reference ... but how ?
}
Thanks for any suggestions.
Is it possible to pass a reference of "this" ? I am extending the MFC CStringArray class. I need to reference the string array using the [] operator, but i cannot do this on a pointer, it needs to be on a reference to the original object. I don't have access to the actual member data (as far as i can tell from the docs)
Am i making this clear ? Here's a code snippet which will explain.
void SortStringArray (CStringArray &csa, BOOL bDescending)
{
int iArraySize = csa.GetSize();
if (iArraySize <= 0)
return;
int iCSSize = sizeof (CString*);
void* pArrayStart = (void *)&csa[0]; // i cannot do this on a pointer, so i cannot pass a "this" pointer to this func
if (bDescending)
qsort (pArrayStart, iArraySize, iCSSize, CompareDescending);
else
qsort (pArrayStart, iArraySize, iCSSize, CompareAscending);
}
void CSortStringArray::QuickSort(bool *pbCancel /* = false */)
{
SortStringArray(this, FALSE); // can't pass "this". Need to pass a reference ... but how ?
}
Thanks for any suggestions.