开发者

Declaring arrays similar to C style (C++)

In C a programmer can declare an array like so:

unsigned char 开发者_Go百科Fonts[2][8] {
    [1] = {0, 31, 0, 31, 0, 31, 0, 31}
};

And element [0] is likely random bits. Is there a similar way in C++?


This works in C++:

unsigned char foo [2][8] = {
        {},
        {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'}
};

Here, foo[0] is zero-initialized as defined by the C++ standard (§8.5.5 - default initialization for POD types is zero-initialization). For non-POD-types the default constructor is called.


You can do this:

unsigned char Fonts[2][8] = {
    {0},
    {0, 31, 0, 31, 0, 31, 0, 31}
};


Why not just do

unsigned char Fonts[2][8] {
    {0, 0, 0, 0, 0, 0, 0, 0},
    {0, 31, 0, 31, 0, 31, 0, 31}
};

?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜