大佬教程收集整理的这篇文章主要介绍了c – 在地图中使用std :: unique_ptr作为关键字,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
std::map<std::string,std::map<std::unique_ptr<sf::Sound>,std::unique_ptr<sf::SoundBuffer>>> listSoundContainer;
我正在尝试插入这样的数据:
std::unique_ptr<sf::SoundBuffer> soundBuffer(new sf::SoundBuffer()); if (soundBuffer->loadFromFile("assets/sound/" + _fileName) != falsE) { std::unique_ptr<sf::Sound> sound(new sf::Sound(*soundBuffer)); typedef std::map<std::unique_ptr<sf::Sound>,std::unique_ptr<sf::SoundBuffer>> innerMap; listSoundContainer[_filename].insert(innerMap::value_type(std::move(sound),std::move(soundBuffer))); }
并在编译时得到以下错误:
我也尝试使用make_pair插入数据同样的问题.我错过了什么?我一直试图解决这个问题2个小时,现在无法理解它.
我实际上可以通过不使用智能指针来解决这个问题:
sf::SoundBuffer* soundbuffer = new sf::SoundBuffer(); soundbuffer->loadFromFile(_filE); sf::Sound* sound = new sf::Sound(*soundbuffer); typedef std::map<sf::SoundBuffer*,sf::Sound*> mapType; listSound[_file].insert(mapType::value_type(soundbuffer,sound));
template< class Key,class T,class Compare = std::less<Key>,class Allocator = std::allocator<std::pair<const Key,T> > > class map;
现在让我们看看你如何尝试实例化它:
std::map< std::string,std::map< std::unique_ptr<sf::Sound>,std::unique_ptr<sf::SoundBuffer> > > listSoundContainer
这里的问题是std :: unique_ptr< sf :: Sound>不能充当关键.
你似乎想做的是制作一些std :: pair< std :: unique_ptr< sf :: Sound>的列表,
的std ::的unique_ptr< SF :: SoundBuffer>>
我建议改用:
std::map< std::string,std::list< std::pair< std::unique_ptr<sf::Sound>,std::unique_ptr<sf::SoundBuffer> > > > listSoundContainer
以上是大佬教程为你收集整理的c – 在地图中使用std :: unique_ptr作为关键字全部内容,希望文章能够帮你解决c – 在地图中使用std :: unique_ptr作为关键字所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。