I really like how Arduino allows you to initialize multi-dimensional arrays with this syntax:
int x [][3]= {
{1,2,3},
{11,22,33}
}
However, this does not seem to work in a Class. Below is a short sketch illustrating the error that I get:
"expected primary-expression before '{' token "
What I'm trying to do is to encapsulate a bunch of multi-dimensional shape arrays into a Shape class so I can instantiate a Tetris piece of a particular shape and rotation. Even if there are better way to do this, I'd still be interested in how to pre-initialize an array without having to do this: x[1][2] = 1 repeatedly for every element.
class MyClass
{
public:
MyClass();
private:
int _predefinedInt;
int * _predefinedArray;
};
MyClass::MyClass()
{
_predefinedInt = 7; // This works fine
// These work fine but too wordy when I have a big multi-dimension array
// _predefinedArray[0] = 1;
// _predefinedArray[1] = 2;
// _predefinedArray[2] = 3;
// *** Error: expected primary-expression before '{' token ***
_predefinedArray = {0,1,2};
};
void setup()
{
MyClass myClass;
// blah blah blah
}
void loop()
{
}