Проблема
У меня есть структура ShipCell, многие из этих структур хранятся в классе Ships. В этом классе я определил метод .removeDuplications(), который выдает ошибку.
Код: Выделить всё
.removeDuplicates()Когда я запускаю функцию или метод внутри .removeDuulates() для объекта класса Ships, в котором необходима итерация, например unique() или .insert(), возникает непредвиденная ошибка. Я думаю, это из-за самой структуры.
Сообщение об ошибке
Сообщение об ошибке очень большое, я постарался включить самую важную часть:
Код: Выделить всё
invalid operands to binary expression ('const ShipCell' and 'const ShipCell')Код: Выделить всё
in instantiation of function template specialization 'std::_Rb_tree::_M_insert_unique' requested hereКод: Выделить всё
candidate template ignored: could not match 'const move_iterator' against 'const ShipCell'
Код: Выделить всё
struct ShipCell
{
int id_track;
int id_marine;
float lat;
float lon;
int speed;
int course;
int age;
std::string date_add;
};
class Ships
{
private:
std::vector ships;
public:
Ships() = default;
Ships(const std::vector &initial_ships)
{
ships = initial_ships;
}
Ships(size_t size) : ships(size) {};
// std::vector methods
void push_back(const ShipCell &cell)
{
ships.push_back(cell);
}
size_t size() const
{
return ships.size();
}
auto begin() { return ships.begin(); };
auto end() { return ships.end(); };
ShipCell &operator[](size_t index) { return ships[index]; };
void removeDuplicates();
};
Код: Выделить всё
void Ships::removeDuplicates()
{
std::set s;
unsigned size = ships.size();
for (unsigned i = 0; i < size; ++i) s.insert(ships[i]); // Error here
}
Подробнее здесь: https://stackoverflow.com/questions/797 ... cture-in-c
Мобильная версия