class UserType
{
int _int;
char _char;
public:
UserType(int i1=0, char i2='a'):_int(i1),_char(i2){};
int operator<(UserType& in) {return this->_int<in._int;};
};
int main(int argc, char* argv[])
{
multiset<UserType> Set;
UserType element1(3,'a'),element2(2,'a');
cout<<(element2<element1);
Set.insert(element1);
getch();
return 0;
}
Как в STL создать множество (нужен ваш анализ кода)
Код:
Ошибка появляется в при применении Set.insert(element1) при сравнивании двух переменных типа UserType, но опреацию сравнени для них я определил...
помогите, как запустить?
А почему бы тебе не использовать std::map ?
И еще - не пробовал делать банарным предикатом, отдельным, и передавать его в конструктор множества, вместо критерия сортировки по дефолту? Может быть, поможет.
Код:
class UserType
{
public:
bool operator<(const UserType& in) const {
return (this->_int < in._int);
}
};
{
public:
bool operator<(const UserType& in) const {
return (this->_int < in._int);
}
};