   My sorting is not working???
  Hi, I am using C++ and D3DXSprite.I have a base struct SPRITEX. There are two derived structs, SPRITEIMAGE and SPRITETEXT. This code draws my sprites or text. A sprite or text object is added to a list of base struct pointers throughout the loop. At the end, the list is sorted and drawn according to the order they are sorted into.The problem is that the sorting has stopped working after I implemented this method of using dynamic_cast. Everything draws fine, just that sorting is not working.//structs, using inheritance//spritex base structstruct SPRITEX {virtual ~SPRITEX(){};float m_fZ;//z (1 close, 5 far)RECT m_recDest;//destination positionbool m_bImage;//image or text   //this operator allows sorting:bool operator<(const SPRITEX &spr) const {return m_fZ>spr.m_fZ;}//operator to sort vertex struct};//spritex component struct that is only for imagesstruct SPRITEIMAGE: public SPRITEX{~SPRITEIMAGE(){};string m_sTextureName;string m_sTileName;float m_fRotation;//rotation in degrees};//spritex component struct that is only for textstruct SPRITETEXT: public SPRITEX{~SPRITETEXT(){};string m_sText;short int m_nAlignment;//left/center/rightbool m_bWraptext;DWORD m_dwColor;//text colorvector<LOADEDFONT*>::iterator m_itFont;//iterator pointing to a font};I add a sprite or text to draw, to the list during the loop with a function like below://adding a sprite image (sprite text works the same way)   SPRITEIMAGE *newSpriteImage=new SPRITEIMAGE;newSpriteImage->m_bImage=true;//etc .....//add sprite to list   //list below is a vector eg vector <SPRITEX*> m_lstSpritexList;m_lstSpritexList.push_back(newSpriteImage);I use this code to draw images or text. I have cut the code down, but everything is there that is needed to know how it works.//loop through list of sprites and text to rendervector<SPRITEX*>::iterator itSprite=m_lstSpritexList.begin();while(itSprite!=m_lstSpritexList.end()){//this object is currently known as the base struct SPRITEX   //below it is discovered that is a derived struct SPRITEIMAGEif((*itSprite)->m_bImage==true){ //it is cast into a SPRITEIMAGE pointerSPRITEIMAGE *pSpriteImage=dynamic_cast<SPRITEIMAGE*>((*itSprite)); //then used //my sprite drawing code works perfectly, except z orderSprites (SPRITEX) are sorted here. The base struct SPRITEX has an operator for sorting.//sort sprites in order of z valuesort(m_lstSpritexList.begin(),m_lstSpritexList.end());Anyone able to help get my sorting working again, thanks.   
  Your program doesn't use the operator< - it sorts the *pointer values*. You need to do something like this:bool compare_SPRITEX_ptr(SPRITEX* a, SPRITEX* b) {  return *a < *b;}sort(spritelist.begin(), spritelist.end(), compare_SPRITEX_ptr);//spritex base structstruct SPRITEX {virtual ~SPRITEX(){};float m_fZ;//z (1 close, 5 far)RECT m_recDest;//destination positionbool m_bImage;//image or text};//compare function for struct SPRITEXstruct CompareSPRITEX : public std::binary_function<SPRITEX*,SPRITEX*,bool> {bool operator()(SPRITEX* a, SPRITEX* b) const {return (a->m_fZ > b->m_fZ);}};This worked.Do you think that my compare function is too complex, ie can it be made more optimised, for comparing a list of 'pointer to objects' using std::sort?   