Problem with qsort() on CArray(ptr *, ptr *)
-
can someone help me? I have a variable declared as CArray<CmyData *, CmyData*> myDataArray; then I try the following:
CmyData** pData = (CmyData **) myDataArray.GetData();
qsort(pData, numItems, sizeof(CmyData *), Compare);Something is whacky with how Compare() function receives the information from pData. Pointers go off to neverland?? Thank you. RESOLVED: My Compare function had to be adjust to handle array of pointers:
myClass::Compare(const void* pEle1, const void* pEle2)
{
CmyData* pData1 = *(CmyData **) pEle1;
CmyData* pData2 = *(CmyData **) pEle2;
// do the comparison, now that the defrenced pointer good}
-
can someone help me? I have a variable declared as CArray<CmyData *, CmyData*> myDataArray; then I try the following:
CmyData** pData = (CmyData **) myDataArray.GetData();
qsort(pData, numItems, sizeof(CmyData *), Compare);Something is whacky with how Compare() function receives the information from pData. Pointers go off to neverland?? Thank you. RESOLVED: My Compare function had to be adjust to handle array of pointers:
myClass::Compare(const void* pEle1, const void* pEle2)
{
CmyData* pData1 = *(CmyData **) pEle1;
CmyData* pData2 = *(CmyData **) pEle2;
// do the comparison, now that the defrenced pointer good}
Perhaps you should give more detail, like exactly what goes wrong, error message, etc..
The difficult we do right away... ...the impossible takes slightly longer.
-
can someone help me? I have a variable declared as CArray<CmyData *, CmyData*> myDataArray; then I try the following:
CmyData** pData = (CmyData **) myDataArray.GetData();
qsort(pData, numItems, sizeof(CmyData *), Compare);Something is whacky with how Compare() function receives the information from pData. Pointers go off to neverland?? Thank you. RESOLVED: My Compare function had to be adjust to handle array of pointers:
myClass::Compare(const void* pEle1, const void* pEle2)
{
CmyData* pData1 = *(CmyData **) pEle1;
CmyData* pData2 = *(CmyData **) pEle2;
// do the comparison, now that the defrenced pointer good}
-
can someone help me? I have a variable declared as CArray<CmyData *, CmyData*> myDataArray; then I try the following:
CmyData** pData = (CmyData **) myDataArray.GetData();
qsort(pData, numItems, sizeof(CmyData *), Compare);Something is whacky with how Compare() function receives the information from pData. Pointers go off to neverland?? Thank you. RESOLVED: My Compare function had to be adjust to handle array of pointers:
myClass::Compare(const void* pEle1, const void* pEle2)
{
CmyData* pData1 = *(CmyData **) pEle1;
CmyData* pData2 = *(CmyData **) pEle2;
// do the comparison, now that the defrenced pointer good}
-
Perhaps you should give more detail, like exactly what goes wrong, error message, etc..
The difficult we do right away... ...the impossible takes slightly longer.
Sorry, i think the brackets watered down my description. I have declared a CArray as:
CArray<CmyData *, CmyData *> myDataArray;
I fill myDataArray correctly using CArray::SetAtGrow(). This is done correctly because I test by iterating through the CArray after i fill it and check all the items in the CmyData object. Then i attempt:
CmyData** pData = (CmyData **) myDataArray.GetData();
// verified both myDataArray and pData can report back my data - iterated thruqsort(pData, numItems, sizeof(CmyData *), Compare);
Then when i look in my Compare() function, the 2 parameters have invalid values. I don't know if there is a problem passing pData like i do OR if my Compare() function is not resolving the 2 parameters correctly. (PS, thanks for the other posts on articles to read..)
-
Thanks! the first link you provided as a reference looks exactly like the setup i am using. I also updated my post under one of the first replys - the < and > brackets may have corrupted my original question. JJM