This works...
but this doesn't work...
If I try to use structs in a std::set I get this error from MSVC:-
C:\Program Files\Microsoft Visual Studio 8\VC\include\functional(143) : error C2784: 'bool std:: operator <(const std::_Tree<_Traits> &,const std::_Tree<_Traits> &)' : could not deduce template argument for 'const std::_Tree<_Traits> &' from 'const my_struct'
C:\Program Files\Microsoft Visual Studio 8\VC\include\xtree(1372) : see declaration of 'std:: operator <'
C:\Program Files\Microsoft Visual Studio 8\VC\include\functional(142) : while compiling class template member function 'bool std::less<_Ty>:: operator ()(const _Ty &,const _Ty &) const'
with
[
_Ty=my_struct
]
std::set is using std:: operator < to determine if the struct is already present in the set - but std:: operator < doesn't seem to work for a struct (presumably, it has no way of knowing how big the struct is). I need to keep std::set for compatibility with something else, so what's the best way to solve this problem? Can I tell std::set to use my own defined comparison operator, instead of std:: operator < ?
Code:
std::set<int> IntSet;
int hello = 6;
IntSet.insert (hello);Code:
typedef struct {
void *p;
unsigned int n;
} my_struct;
std::set<my_struct> StructSet;
my_struct goodbye;
goodbye.p = whatever();
goodbye.n = 1;
StructSet.insert (goodbye);Quote:
C:\Program Files\Microsoft Visual Studio 8\VC\include\functional(143) : error C2784: 'bool std:: operator <(const std::_Tree<_Traits> &,const std::_Tree<_Traits> &)' : could not deduce template argument for 'const std::_Tree<_Traits> &' from 'const my_struct'
C:\Program Files\Microsoft Visual Studio 8\VC\include\xtree(1372) : see declaration of 'std:: operator <'
C:\Program Files\Microsoft Visual Studio 8\VC\include\functional(142) : while compiling class template member function 'bool std::less<_Ty>:: operator ()(const _Ty &,const _Ty &) const'
with
[
_Ty=my_struct
]