Pointer to iterator is not properly working

So when I do this
1
2
3
4
5
6
7
8
9
10
11
12
13
auto iterator = listeners_[event->type].begin();

		while (iterator != listeners_[event->type].end()) {

			iterator->function(event);

			updateEvents(event->type, &iterator);//this will ++it

		}

		std::list<Listener>::iterator* iterator_point = &iterator;

		iterator_point->//there is no Listener's memembers (name, id...) 

Pointer to iterator doesn't shows any of the Listener's members.
Last edited on
You need to dereference the pointer first.

 
(*iterator_point)->
And also how can I increment iterator's pointer?
iterator++ and (*iterator)++ doesn't work.
The iterator is already pointing to the end so it is not possible to go any further.
I don't understand. My iterator is stuck at first element.
In 'updateEvents' method, is this code that doesn't work:
*iterator++
OK, I thought it was after the loop as it appears in the code.

If the pointer is called iterator_point you can increment the iterator by doing (*iterator_point)++.
I already tried that and nothing. Btw your first answer works for Listener's members.
Nothing what? It's difficult guess what the problem is without seeing the code.
I know iterator is stuck at first element because cout is printing the first initialized element over and over. And just ignore logical code, we are focusing on incrementing iterator.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
	void EventManager::updateEvents(sf::Event::EventType event_type, std::list<Listener>::iterator* iterator) {

		initializeListenerUpdates(event_type, iterator);

	}

	void EventManager::initializeListenerUpdates(sf::Event::EventType event_type, std::list<Listener>::iterator* iterator) {
		std::cout << (*iterator)->name << std::endl;

		for (auto& listener_update : listener_updates_) {

			if (listener_update.to_remove_ && containsListener(listener_update.event_type, listener_update.name)) {

				bool match = false;

				if (listener_update.event_type == event_type && (*iterator)->name == listener_update.name) {

					match = true;

					(*iterator)++;

				}

				if (listeners_[listener_update.event_type].size() <= 1) {

					listeners_.erase(listener_update.event_type);

					continue;
				}

				deleteListener(listener_update.event_type, listener_update.name);

				if (!match) (*iterator)++;

			} else if (!listener_update.to_remove_ && !containsListener(listener_update.event_type, listener_update.name)) {

				(*iterator)++;

				if (listeners_.find(listener_update.event_type) == listeners_.end()) {

					std::list<Listener> event_type_functions_list;

					event_type_functions_list.push_back(Listener(listener_update.name, listener_update.function));

					listeners_[listener_update.event_type] = event_type_functions_list;

				} else {

					if (containsListener(listener_update.event_type, listener_update.name)) return;

					listeners_[listener_update.event_type].push_back(Listener(listener_update.name, listener_update.function));

				}

			}

		}

		listener_updates_.clear();

	}
Last edited on
If the iterator is not incremented it's probably because none of the (*iterator)++; statements are being executed.
Last edited on
You are right, the problem is somewhere in logic. Thank you very much! I wish this site had an like button or something like that.
Topic archived. No new replies allowed.