Hey guys need some help with this.
I m kinda new to c++. I m trying to insert a structure into a set. and when i compile this i m a gettin an error. i guess i need to add a comparator function please let me how do i do that.
Thanks.
#include <iostream>
#include <set>
#include <algorithm>
typedef struct _CONFIG_
{
char app[10];
char key[10];
}config_line;
/*struct classcomp {
bool operator() (const char *lhs, const char *rhs) const
{
int rc = strcmp(lhs,rhs);
if(rc>0)
return FALSE;
else if(rc<0)
return TRUE;
else
return FALSE;
};*/
int main()
{
config_line data;
std::set<config_line> nbabudir_set;
strcpy(data.app,"app1");
strcpy(data.key,"key1");
nbabudir_set.insert(data);
}
Error thrown my gcc is
/usr/sfw/lib/gcc/sparc-sun-solaris2.10/3.4.3/../../../../include/c++/3.4.3/bits/stl_function.h: In member function `bool std::less<_Tp>::operator()(const _Tp&, const _Tp&) const [with _Tp = config_line]':
/usr/sfw/lib/gcc/sparc-sun-solaris2.10/3.4.3/../../../../include/c++/3.4.3/bits/stl_tree.h:869: instantiated from `std::pair<typename std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator, bool> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::insert_unique(const _Val&) [with _Key = config_line, _Val = config_line, _KeyOfValue = std::_Identity<config_line>, _Compare = std::less<config_line>, _Alloc = std::allocator<config_line>]'
/usr/sfw/lib/gcc/sparc-sun-solaris2.10/3.4.3/../../../../include/c++/3.4.3/bits/stl_set.h:314: instantiated from `std::pair<typename std::_Rb_tree<_Key, _Key, std::_Identity<_Key>, _Compare, _Alloc>::const_iterator, bool> std::set<_Key, _Compare, _Alloc>::insert(const _Key&) [with _Key = config_line, _Compare = std::less<config_line>, _Alloc = std::allocator<config_line>]'
set.cpp:32: instantiated from here
/usr/sfw/lib/gcc/sparc-sun-solaris2.10/3.4.3/../../../../include/c++/3.4.3/bits/stl_function.h:227: error: no match for 'operator<' in '__x < __y'