Creating a composite type from two enum classes, ready for STL map

后端 未结 6 1686
星月不相逢
星月不相逢 2021-02-14 05:26

I would like to create a composite type out of two enum classes.

enum class Color {RED, GREEN, BLUE};
enum class Shape {SQUARE, CIRCLE, TRIANGLE};

         


        
6条回答
  •  走了就别回头了
    2021-02-14 05:41

    That's a good question, but you don't actually need the number of Color to compare them :

    friend bool operator< (const Object &lhs, const Object &rhs) {
        if(lhs.color > rhs.color) {
            return false;
        }
        if(lhs.color < rhs.color) { 
            return true;
        }
        return lhs.shape < rhs.shape;
    }
    

提交回复
热议问题