vendredi 3 juillet 2015

c++ enum class inside std::multimap

I'm having 2 enum's which are of the newer enum class type.

enum class Action
{
    Move,
    Attack,
    Die,
    Splash,
    Idle
};

enum class Facing
{
    Left,
    LeftUp,
    LeftDown,
    Up,
    Down,
    Right,
    RightUp,
    RightDown
};

And I want to store this stuff inside a multimap:

std::multimap<Entity::Facing,std::pair<Entity::Action,std::unique_ptr<Animation>>> listAnimation;

The key is: facing and the pair is the action of the entity + the animation.

This is how i insert it:

std::unique_ptr<Animation> splashUp (new Animation());
splashUp->setSpriteSheet(*texture);
splashUp->addFrame(sf::IntRect(3584,256,128,128));
splashUp->addFrame(sf::IntRect(3712,256,128,128));
splashUp->addFrame(sf::IntRect(3840,256,128,128));
splashUp->addFrame(sf::IntRect(3968,256,128,128));
splashUp->addFrame(sf::IntRect(4096,256,128,128));
splashUp->addFrame(sf::IntRect(4224,256,128,128));
splashUp->addFrame(sf::IntRect(4352,256,128,128));
splashUp->addFrame(sf::IntRect(4480,256,128,128));

this->listAnimation.insert(Entity::Facing::Up, std::make_pair(Entity::Action::Splash, std::move(splashUp)));

and this is the error which I can't wrap my head around even after alot of googling:

error C2664: 'std::_Tree_iterator<_Mytree> std::multimap<_Kty,_Ty>::insert(std::_Tree_const_iterator<_Mytree>,const std::pair<_Ty1,_Ty2> &)' : cannot convert parameter 1 from 'Entity::Facing' to 'std::_Tree_const_iterator<_Mytree>' 1>
with 1> [ 1>
_Mytree=std::_Tree_val>>>>, 1> _Kty=Entity::Facing, 1>
_Ty=std::pair>, 1> _Ty1=const Entity::Facing, 1> _Ty2=std::pair> 1> ] 1> and 1> [ 1>
_Mytree=std::_Tree_val>>>> 1> ] 1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called

Can I use enum class as Key in multimap at all?

Aucun commentaire:

Enregistrer un commentaire