×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    40

    How to sort CArrayPtrFlat<T>?

    Hi all,

    How to sort an array of type CArrayPtrFlat<CMyClass>, which containg pointer to CMyClass as elements?

    I have tried to use something like this,
    //---------------------
    //create the array
    CArrayPtrFlat<CMyClass>* iArray = new (ELeave) CArrayPtrFlat<CMyClass>(16);

    //assume serveral some elements are put into the array like this:
    CMyClass* iElement = new (ELeave) MyClass;
    iArray->AppendL(iElement);

    //then i prepare the key for sorting.
    //iString is a public member of type TBuf
    TKeyArrayFix iKey(_FOFF(CMyClass, iString),ECmpFolded);

    //it is supposed to sort the array according to the iString of each elment
    iArray->Sort(iKey);
    //---------------------

    Buf the array is not sorted correctly as i print out the string usign the loop
    for( TInt i = 0 ; i < iArray->Count(); i++)
    Rebug::Print (iArray->At(i)->iString);

    Could anyone tell what is wrong in my code?
    I suspected that may be related to the usage of CArrayPtrFlat.

    Thank you very much.

    Martin.

  2. #2
    Regular Contributor
    Join Date
    Mar 2003
    Posts
    59

    Use TKeyArrayFixPtr

    The documentation is a bit misleading as it directs you to the base class.

    You need to include "msvarray.h" and link to "msgs.lib".

  3. #3
    Registered User
    Join Date
    Mar 2003
    Posts
    40
    Really thanks.
    But is it enough that just to include the msvarray.h" and link to "msgs.lib"?
    Thanks.
    Martin.

Posting Permissions

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