vendredi 26 mai 2017

Initialize a two dimensual std::array of type enum class (C++11)

I have the following class in C++11:

class MyTable
{
    public:
    enum class EntryType
    {
        USED, FREE
    };

    MyTable(EntryType value)
    {
        for (uint32_t i = 0; i < 10; ++i)
        {
            memset(_table[i].data(), (int)value, sizeof(_table[0][0]) * 50);
        }
    }
    array<array<EntryType, 50>, 10> _table;
}

Trying to construct an object of MyTable with value of EntryType::FREE, every item in the 2 dimensional has the value of 0x01010101 (1b every 8 bits), instead of the expected value of just 0x1

I'm guessing it has something to do with my value being casted to int, but I don't know what I'm supposed to do in order to fix it.

Aucun commentaire:

Enregistrer un commentaire