I need to sort my custom class based on the std struct tm object. I would like to know if I am approaching this correctly and ask for suggestions for the comparison function. Originally, I was converting each std::tm member to some base number (like Ticks in .NET DateTime), but I thought that might be excessive.
I don’t have to use a list, but I do have to use a Container<MyClass*>. I would prefer the list, though. This is my custom class:
class MyClass
{
public:
std::tm _datetime;
static bool ComparePointers(MyClass*& lhs, MyClass*& rhs);
};
bool MyClass::ComparePointers(MyClass*& lhs, MyClass*& rhs)
{
// ??
}
This is my main function:
int main()
{
std::list<MyClass*> classes;
MyClass* class_1 = new MyClass(); classes.push_back(class_1);
MyClass* class_2 = new MyClass(); classes.push_back(class_2);
MyClass* class_3 = new MyClass(); classes.push_back(class_3);
list.sort(MyClass::ComparePointers);
}
You can use
mktimeto convert astd::tmvalue to atime_twhich can be compared.