我正在尝试用C ++创建一个俄罗斯方块克隆,我希望将这些片段存储在一个多维数组中。我在我的头文件中声明它如下:
class Pieces
{
public:
Pieces();
private:
int pieces[7][4][5][5];
};
我正在尝试在构造函数中初始化它:
Pieces::Pieces()
{
pieces[7][4][5][5] = { /* ... all of the pieces go in here ... */ };
}
但这不起作用,我得到这样的错误:
src/Pieces.cpp:5:17: error: cannot convert ‘<brace-enclosed initializer list>’ to ‘int’ in assignment
如何声明和初始化此数组?
答案 0 :(得分:4)
在C ++ 11中:
Pieces::Pieces()
: pieces{ /* ... all of the pieces go in here ... */ }
{
}
在C ++ 03中:
Pieces::Pieces()
{
// iterate over all fields and assign each one separately
}