pointer in for auto for vector of poitners causes fatal error

As title says i got fatal error from for (auto object : Object::getObjects()) when the std::cout << *object->getName(); is called. Here is my code:
http://pastebin.com/C0rpAzU7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
	std::vector<Object*> getObjects() {

		std::vector<Object*> objects_c2;

		objects_c2.reserve(objects.size());

		for (auto object : objects) {

			objects_c2.push_back(&object.second);

		}
		
		return objects_c2;
	}

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
	void updateGame() {

		int ball_position_main_x = 50, ball_position_main_y = 50;

		float f = 0;

		int interval = 0;

		for (auto objectC : Object::getObjects()) {

			std::cout << *objectC->getName() << "s";

		} //ERROR IS HERE

		while (game_run) {

			Object::Object* object = Object::getObject("test");

			//std::cout << object->getPosition().x << ", " << object->getPosition().y << std::endl;

			sf::sleep(sf::milliseconds(10));

		}

	}


Every time when I create a new topic code button is not working for me.
*objectC->getName()
the `->' operator would already dereference the pointer, ¿why do you need the `*'?

1
2
3
4
5
6
		for (auto object : objects) { //a copy
			objects_c2.push_back(&object.second); //taking the address of a copy
		}

for( auto &object: objects ) //a reference, an alias
   objects_c2.push_back(&object.second); //taking the address of the object in the container 



You ought to provide a minimal code snip that does reproduce your issue.
Thank you very much, you saved my time.
Printing objectC->getName() to the console will only print address of the pointer. Is there something wrong in my code?
Last edited on
would need to see `getName()' code.
Topic archived. No new replies allowed.