-3

How do I make this work? I tried this, but no bueno. Basically, as it is, it says "for" needs a declaration, meaning there's something going on with the initialization part. I already know how to set one up. I just need to get past this part. However, if anyone can give me an alternative to making a list (or sequence container) of multidimensional arrays, that will be great, too.

#include <list>
#include <vector>
using namespace std;

class MainTetris
{
    /*
        Creating a list of multidimensional vectors to represent each tetris piece.
        Don't plan on dynamically growing them in the game. It's only because
        STL list doesn't hold arrays.
    */

    list<vector< vector<int> > > pieces;

}
Benjamin Lindley
  • 101,917
  • 9
  • 204
  • 274
Cdore
  • 107
  • 1
  • 11

2 Answers2

1

You need to separate the angle brackets.

list<vector<vector<int> > > pieces;

Also you are trying to push a vector<int> instead of a vector<vector<int> >

bottlecap
  • 11
  • 2
  • I did so, but still the same error of "expecting declaration." – Cdore Mar 13 '13 at 05:10
  • "Also you are trying to push a vector instead of a vector >" - The single vector is to initialize seven rows. The vector starts out empty, so I need to fill it in before I start being able to use it like a normal array, i.e. vector[0][0]. – Cdore Mar 13 '13 at 05:15
  • As Benjamin said, that for loop needs to go in a member function. You'll still need to fix the fact that you are pushing the wrong type onto the list though. – bottlecap Mar 13 '13 at 05:28
  • Ah, so it seems I need to fill up both rows and columns, then. – Cdore Mar 13 '13 at 05:36
0

You can't have a for loop in a class body. It must be in a function. You probably want it in your constructor. Where did you learn to write classes that way? Any introductory book would have covered this fairly early on.

The Definitive C++ Book Guide and List

Community
  • 1
  • 1
Benjamin Lindley
  • 101,917
  • 9
  • 204
  • 274
  • I actually meant for it to be in the constructor. I was just writing on the fly. Been studying a lot of web code lately, so constructors haven't been on my mind till today. lol – Cdore Mar 13 '13 at 05:23
  • @Cdore: Are you saying that the code you presented was not actually the code you tried to compile? – Benjamin Lindley Mar 13 '13 at 05:27
  • I'm not compiling any code as of yet. But I do admit that my brain wasn't thinking about constructors since languages such as php and javascript don't care for them. I know how to code in C++, but I've been out of it for a couple of months. – Cdore Mar 13 '13 at 05:31
  • @Cdore: You're not making any sense. If you're not compiling anything, what program is reporting that your code has an error? – Benjamin Lindley Mar 13 '13 at 05:33
  • Visual studio's real time error catching. It was a dumb moment for me until I realized that I was still in class initialization scope. – Cdore Mar 13 '13 at 05:35