[Solved] Change the order of a std::set as a member attribute [closed]


Something like that?

class CustomObject{
public:
    CustomObject(int _x) : x(_x) {};
    int x;
};

struct cmpStruct {
    bool operator() (const CustomObject*  lhs, const CustomObject*  rhs) const
    {
        return lhs->x > rhs->x;
    }
};

int main(int argc, char* argv[])
{
    std::set<CustomObject*, cmpStruct> container;

    CustomObject a(10);
    CustomObject b(20);
    CustomObject c(5);

    container.insert(&a);
    container.insert(&b);
    container.insert(&c);

    for(auto co : container) {
        std::cout << co->x << std::endl;
    }
    return 0;
}

Output:

20
10
5

2

solved Change the order of a std::set as a member attribute [closed]