OS: Fedora 21
GCC Ver 4.9.2
Codeblocks Ver 10253 (compiler set to "have g++ follow C++ 11 ISO C++ language standards.")
Error: "Spreadsheet.h|34|error: ISO C++ forbids in-class initialization of non-const static member ‘Spreadsheet::sCounter’|"
EDIT: Please don't point me to work arounds. I already know them. I want to know if the book is wrong and in-class initialization of static variables is C++ 11 compliant or not.
This code is from Professional C++ by Gregoire and others. This is the first time GCC has not been able to compile C++ 11 code from this text.
The following code (see last line) results in the error:
/ Spreadsheet.h
#include "SpreadsheetCell.h"
class SpreadsheetApplication; // forward declaration
class Spreadsheet
{
public:
Spreadsheet(int inWidth, int inHeight,
const SpreadsheetApplication& theApp);
Spreadsheet(const Spreadsheet& src);
~Spreadsheet();
Spreadsheet& operator=(const Spreadsheet& rhs);
void setCellAt(int x, int y, const SpreadsheetCell& cell);
SpreadsheetCell getCellAt(int x, int y);
int getId() const;
// Doesn't work in Microsoft Visual Studio 6
static const int kMaxHeight = 100;
static const int kMaxWidth = 100;
protected:
bool inRange(int val, int upper);
void copyFrom(const Spreadsheet& src);
int mWidth, mHeight;
int mId;
SpreadsheetCell** mCells;
const SpreadsheetApplication& mTheApp;
static int sCounter = 0; // Produces Error
};