error: a brace-enclosed initializer is not allowed here before '{' token

The following code compiles fine on g++ version 4.8.1 :slight_smile: but gets a compile error on Arduino IDE 1.0.5 :~.

class Proc: public Matrix
{
    private:
	R1 row0;
	R1 row1;
	R2 row2;
	Row * const row[numRows] = { &row0, &row1, &row2 }; /*** this line 16 gets the error ***/
    public:
	Row * const getRow(const uint8_t rowN) { return row[rowN]; };
	void read(const uint8_t rowN);
};

Proc.h:16: error: a brace-enclosed initializer is not allowed here before '{' token

I am compiling on Arduino IDE 1.0.5, which seems to be using avr-g++ 4.3.2:

...\arduino-1.0.5\hardware\tools\avr\bin\avr-g++ --version
avr-g++ (WinAVR 20081205) 4.3.2
... g++ --version
g++ (GCC) 4.8.1

This post said it is a bug that was fixed on version 4.7.0:

If this is indeed a bug, is there a work around?

Thank you.

Normally, variables are defined in a header file and initialized in a source file. Why are you not normal?

Thanks PaulS. I moved the initialization into the constructor and that fixed it.

After fixing some other compile errors, the compiler complained about the initialization again.
My understanding is that initialization lists are needed to initialise const variables on the line that they are declared.
How is that done for an array of const pointers? This syntax did not work:

class Proc: public Matrix
{
    private:
	R1 row0;
	R1 row1;
	R2 row2;
	Row * const row[numRows];
    public:
	Proc(): row[0](&row0), row[1](&row1), row[2](&row2) { }; /*** this line 20 errors ***/
	Row * const getRow(const uint8_t rowN) { return row[rowN]; };
	void read(const uint8_t rowN);
};

Proc.h:20: error: expected (' before '[' token Proc.h:20: error: uninitialized member 'Proc::row' with 'const' type 'Row* const [3]' Proc.h:20: error: expected {' before '[' token

I think that the first thing you need to do is quit trying to initialize anything in the header file.

I think that the second thing you need to do is define what, exactly, need to be const. If the pointer supposed to be const, so it can't be pointed anywhere else? Or, is the pointer memory supposed to be const, so you can't change the memory that it points to.

I'd try writing the code without worrying about const-ness. When the code works when you are careful not to fk with stuff you aren't supposed to fk with, then you can add the const qualifier, to prevent other people from fking with stuff they aren't supposed to fk with.

Thanks PaulS. That's some good advice.
This works:

class Proc
{
    private:
	R1 row0;
	R1 row1;
	//Row * const row[numRows] = { &row0, &row1 };//worked in g++, use it on next version of ino
	// ino error: a brace-enclosed initializer is not allowed here before '{' token
	Row * row[numRows];
    public:
	Proc();
	Row * getRow(int r) { return row[r]; };
};

Proc::Proc() // this worked on Arduino 1.0.5
{
	row[0]=&row0;
	row[1]=&row1;
}