Znajdowanie i usuwanie elementu z wektora

0

Próbuję usunąć element z wektora poprzez wykorzystanie iterator i otrzymuję taki błąd:
Error C2678 binary '==': no operator found which takes a left-hand operand of type 'Position::Object' (or there is no acceptable conversion)

struct Object {
	unsigned int value;
	Object* pointer;
};

std::vector<Object> items;
std::vector<Object> temp;

Object *wsk = &items[0];

for (auto obj : items) {
	if (obj.pointer == wsk) break;
	else {
		temp.push_back(obj);
		auto it = std::find(items.begin(), items.end(), obj);
		items.erase(it);
	}
1

Nie masz zdefiniowanego operatora== dla Twojej struktury.

0

Zrobiłem tak:

struct Object {
		unsigned int value;
		Object* pointer;
	public:
		bool operator==(Object& el);
	};

bool Position::Object::operator==(Object & obj)
{
	if (this->value == obj.value && this->pointer == obj.pointer) return true;
	else return  false;
}

Czy muszę przeciążanie poza strukturą robić?

2

const to nie jest jakaś zabawka którą się ignoruje.

bool operator==(Object const& el) const;

1 użytkowników online, w tym zalogowanych: 0, gości: 1