How to override opCmp when two different sorts are needed?

John Bartelt bartelt at cox.net
Mon Aug 13 17:53:41 PDT 2007


I have a class that contains two variables. Sometimes I need to sort an array of the class based on variable 1, and later in the same progam sort the array based on variable 2.

Can someone give me an idea of how to do this (smartly, efficiently, cleverly, polymorphically, ...)?

Best idea that I've had so far is to use a static flag in the class to indicate which sort is desired, and then to have the overloaded opCmp() check the flag before comparing.



More information about the Digitalmars-d mailing list