Creating a 2D array within a class using a constant

I've been given specific instructions to create an array inside a Class Matrix using a constant n. This is my class but I am getting errors. I thought that maybe I had to initialize the const and the array using the constructor function Matrix() instead of directly in the class, but I didn't have any luck with that either. If anyone can help me out I would really appreciate it.

class Matrix
{
public:
Matrix();


private:
const int n=3;
int e[n][n];

};
Does the const have to be a member of the class? Because you just move const int n = 3; to before the class definition and that would work.
Yeah, the constant has to be a member variable. I was under the impression that you couldn't initialize a variable inside a class but the example my instructor is giving me looks exactly like what I have but still doesn't work :/

My compiler gives me this.
warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11 [enabled by default]

You either need to use a c++11 compiler or make the variable a static variable (by adding the word static at the front).


Thanks for the help. I ended up using Keene's approach until I can get more information from my instructor.
Topic archived. No new replies allowed.