我有一个继承自类案例的类 Block :
class Case {
public:
Case(sf::Vector2f const& pos, sf::IntRect const& textureRect, int type = 1);
protected:
int type_;
sf::Vector2f pos_;
sf::FloatRect hitBox_;
sf::IntRect textureRect_;
};
class Block : public Case {
public:
Block(sf::Texture* const& texture, sf::Vector2f const& pos, sf::IntRect const& textureRect, int const& type = 2);
sf::Sprite& getSprite();
private:
std::shared_ptr<sf::Texture> texture_;
sf::Sprite sprite_;
};
(两个构造函数都非常基本,我没有在任何地方使用任何新的)
我有一个无序地图的 unordered_map 来存储我的块:
std::unordered_map<int, std::unordered_map<int, Block>> blocks_;
但是当我尝试删除一个时:
if(blocks_[i%lenght].find((i-i%lenght)/lenght) != blocks_[i%lenght].end())
blocks_[i%lenght].erase((i-i%lenght)/lenght);
我得到那些错误:
double free or corruption (out)
我试图打印析构函数,在我得到这个错误之前只调用了 Block 的析构函数。
大约2个小时我正在寻找解决方案,所以我终于在这里问了,谢谢!