문제

I made an Animation.cpp for my LED cube containig a 2dimensional array of uint16_t for each frame and each layer. I initialize the array in the .cpp and also have a var containing the amount of frames. But when it's running, the array seems to only have random data (from the ram) and the int w/ amount of frames is 0.

link to cpp: http://hastebin.com/kunemopece.avrasm

link to header: http://hastebin.com/duvijipeya.vala

I'm pretty much a beginner in CPP/GCC, so, what did I do wrong?

도움이 되었습니까?

해결책

In C++11, you may directly do that:

class Animation
{
public:
    std::uint16_t frames[8][4] = {
        {0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF},
        {0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF},
        {0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF},
        {0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF},
        {0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF},
        {0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF},
        {0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF},
        {0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF}
    };
    std::uint8_t currentFrame = 0;
};

In C++03, you have to use the constructor:

class Animation
{
public:
    Animation() : currentFrame(0)
    {
        for (int i = 0; i != 8; ++i) {
            for (int j = 0; j != 4; ++j) {
                frames[i][j] = 0xFFFF;
            }
        }
    }

    uint16_t frames[8][4];
    uint8_t currentFrame;
};

다른 팁

Definition of frames in your class is different set of frames that you define in cpp. Try initialising your frames in Animation class constructor.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top