Reputation: 711
I'm trying to create a Tetris clone in C++ and I want to store the pieces in a multidimensional array. I declare it in my header file like this:
class Pieces
{
public:
Pieces();
private:
int pieces[7][4][5][5];
};
And I'm trying to initialize it in the constructor:
Pieces::Pieces()
{
pieces[7][4][5][5] = { /* ... all of the pieces go in here ... */ };
}
But this doesn't work and I get an error like this:
src/Pieces.cpp:5:17: error: cannot convert ‘<brace-enclosed initializer list>’ to ‘int’ in assignment
How can I declare and initialize this array?
Upvotes: 0
Views: 211
Reputation: 48447
In C++11:
Pieces::Pieces()
: pieces{ /* ... all of the pieces go in here ... */ }
{
}
In C++03:
Pieces::Pieces()
{
// iterate over all fields and assign each one separately
}
Upvotes: 4