Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Static C++ map initialization error C2552: non-aggregates cannot be initialized with initializer list

I'm trying to initialize a map in a header with the following code, but it keeps giving me the error in the title. I'm using C++11, so this should be possible, right?

typedef std::map<NPCAnimation::ID, std::map<Direction::ID, sf::Time>> AnimationSpeedMap;
AnimationSpeedMap AnimationSpeeds = {
    {NPCAnimation::WALK, {
            {Direction::LEFT, sf::milliseconds(100)},
            {Direction::RIGHT, sf::milliseconds(100)},
            {Direction::UP, sf::milliseconds(200)},
            {Direction::DOWN, sf::milliseconds(200)}
        }
    },

    {NPCAnimation::IDLE, {
            {Direction::LEFT, sf::milliseconds(600)},
            {Direction::RIGHT, sf::milliseconds(600)},
            {Direction::UP, sf::milliseconds(600)},
            {Direction::DOWN, sf::milliseconds(600)}
        }
    },

    {NPCAnimation::SPECIAL, {
            {Direction::LEFT, sf::milliseconds(500)},
            {Direction::RIGHT, sf::milliseconds(500)},
            {Direction::UP, sf::milliseconds(500)},
            {Direction::DOWN, sf::milliseconds(500)}
        }
    },
};

Thanks in advance! ~ grambler1

like image 659
BarrensZeppelin Avatar asked Jul 29 '13 15:07

BarrensZeppelin


2 Answers

VS2012 supports the initializer list syntax, but the VS2012 implementation of std::map does not. You'll have to wait for support for this to be added.

like image 119
John Dibling Avatar answered Oct 22 '22 19:10

John Dibling


I had the same issue. Unfortunately bracket-initialization and many other C++11 features are not supported until VS2013.

proof: http://msdn.microsoft.com/en-us/library/vstudio/bb386063(v=vs.120).aspx

like image 21
tomi.lee.jones Avatar answered Oct 22 '22 20:10

tomi.lee.jones