W
William Payne
Hello, I have two structs:
struct FileEntry
{
FileEntry(const char* name,
const char* type,
std::size_t file_size,
HICON icon)
:
m_file_size(file_size),
m_icon(icon)
{
std::strcpy(m_name, name);
std::sprintf(m_file_size_as_string, "%u KB", m_file_size / 1024);
}
char m_name[MAX_PATH + 1];
char m_type[64];
std::size_t m_file_size;
char m_file_size_as_string[32];
HICON m_icon;
};
struct FolderEntry
{
FolderEntry(const char* name,
const char* type,
HICON icon)
:
m_icon(icon)
{
std::strcpy(m_name, name);
std::strcpy(m_type, type);
}
char m_name[MAX_PATH + 1];
char m_type[64];
HICON m_icon;
};
and in my program I have two std::vector, one containing FileEntry one
containing FolderEntry. I need to sort these vectors on a single member
variable in each struct. The FileEntry struct may be sorted depending on
name, size or type. The FolderEntry struct may be sorted on name or type. So
how do I do this on the best way? I cannot overload the comparison operator
because I don't know which data member I will base may sort on, or can I?
Please advise on how I should proceed.
Thanks for any replies
/ WP
struct FileEntry
{
FileEntry(const char* name,
const char* type,
std::size_t file_size,
HICON icon)
:
m_file_size(file_size),
m_icon(icon)
{
std::strcpy(m_name, name);
std::sprintf(m_file_size_as_string, "%u KB", m_file_size / 1024);
}
char m_name[MAX_PATH + 1];
char m_type[64];
std::size_t m_file_size;
char m_file_size_as_string[32];
HICON m_icon;
};
struct FolderEntry
{
FolderEntry(const char* name,
const char* type,
HICON icon)
:
m_icon(icon)
{
std::strcpy(m_name, name);
std::strcpy(m_type, type);
}
char m_name[MAX_PATH + 1];
char m_type[64];
HICON m_icon;
};
and in my program I have two std::vector, one containing FileEntry one
containing FolderEntry. I need to sort these vectors on a single member
variable in each struct. The FileEntry struct may be sorted depending on
name, size or type. The FolderEntry struct may be sorted on name or type. So
how do I do this on the best way? I cannot overload the comparison operator
because I don't know which data member I will base may sort on, or can I?
Please advise on how I should proceed.
Thanks for any replies
/ WP