I'm with c++11. I'm trying to initialice a multidimensional array. The first try was
const static int COORDINATES[4][4][2]={{{-1,-1},{0,0},{1,1},{2,0}},
{{-1,1},{0,0},{1,-1},{0,-2}},
{{1,1},{0,0},{-1,-1},{-2,0}},
{{1,-1},{0,0},{-1,1},{0,2}}};
Compiler complained about a constexpr, so I wrote
constexpr const static int COORDINATES[4][4][2]={{{-1,-1},{0,0},{1,1},{2,0}},
{{-1,1},{0,0},{1,-1},{0,-2}},
{{1,1},{0,0},{-1,-1},{-2,0}},
{{1,-1},{0,0},{-1,1},{0,2}}};
No erros, but when I use the array in a method, get an error. I don't understand...
void LShape::rotateShape(Square* cloneSquares) {
int var=COORDINATES[1][1][1]; //no problems
int x=2;
var=COORDINATES[0][x][0]; //error 'not defined' because of x
//if changed to number, works
}
The error:
LShape.cpp:23: referencia a `LShape::COORDINATES' sin definir //reference to L...S not defined
Where line 23 is the second use of COORDINATES
My complete code, LShape header
#ifndef LSHAPE_H
#define LSHAPE_H
#include "Square.h"
#include "EmptySquare.h"
#include "Shape.h"
class LShape : public Shape {
public:
LShape();
LShape(const LShape& orig);
virtual ~LShape();
inline int getState() {return state;}
inline int getNUMBER_OF_STATES() {return NUMBER_OF_STATES;}
inline int getNUMBER_OF_SQUARES() {return NUMBER_OF_SQUARES;}
void rotateShape(Square* cloneSquares);
private:
int state;
static const int NUMBER_OF_STATES=4;
static const int NUMBER_OF_SQUARES=4;
constexpr const static int INITIAL_COORDINATES[3][2]={{1,0},{1,0},{1,1}};
constexpr const static int COORDINATES[4][4][2]={{{-1,-1},{0,0},{1,1},{2,0}},
{{-1,1},{0,0},{1,-1},{0,-2}},
{{1,1},{0,0},{-1,-1},{-2,0}},
{{1,-1},{0,0},{-1,1},{0,2}}};
};
#endif /* LSHAPE_H */
LShape code
#include "../../include/LShape.h"
LShape::LShape() : Shape(){
//numberSquares=4;
//squares = new Square[numberSquares];
}
LShape::~LShape(){
//dtor
}
LShape::LShape(const LShape& other){
//copy ctor
}
void LShape::rotateShape(Square* cloneSquares) {
int var=COORDINATES[1][1][1]; //no problems
int x=2;
var=COORDINATES[0][x][0]; //error not defined
}
By the way, I'm newbie in C++, don't be bad with me :)
EDIT: I'm using the default compiler in linux (GCC) the IDE is using the following command
g++ -std=c++11 -c -g -MMD -MP -MF "build/Debug/GNU-Linux-x86/src/shape/LShape.o.d" -o build/Debug/GNU-Linux-x86/src/shape/LShape.o src/shape/LShape.cpp