0

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?

1
  • Put pieces in the member initializer list of the constructor. Commented Aug 22, 2014 at 6:33

1 Answer 1

4

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
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.