Help for map<std::string, MyObj*>

Hello, first of all sorry for my english, I'm french :).
I'm trying to do a little game (with sfml) and I use the container std::map for manage my object. I'm putting in 3 kind of Object: Paddle, Ball and Brick. However I have to put many Brick in my std::map. I did :

1
2
3
4
5
6
7
8
9
  Bricks * p_Bricks;
  ManagerObj mapManager;
  for (unsigned i = 0; i < 5; ++i)
  {
	p_Bricks = new Bricks();
	p_Bricks->setPosition(BrickSeparation, 100); 
	mapManager.addObj("Brick", p_Bricks);
  }



the .h of ManagerObj is

1
2
3
4
5
6
7
8
9
10
11
#pragma once
class ManagerObj
{
	std::map<std::string, Blocks*> m_Map;
public:
	ManagerObj();
	virtual ~ManagerObj();
	void addObj(std::string nameObj, Blocks* BlockObj);
	void deleteObj(std::string nameObj, Blocks* p_Block);
	void drawAll(sf::RenderWindow & window);
};


ManagerObj has to arrange the objects for update but I need to stock some different Bricks for delete them one by one. However the pointer address is always the same.

Can you help me please ?


std::map<> does not allow duplicate keys so only one pair with the key "Bricks" is in the map. You can use a std::multimap<> which allows for duplicate keys.
Last edited on
Ok thanks a lot :)
Do you really need the key? Why not just use a std::vector<Block>?
Topic archived. No new replies allowed.