Define non-const private static data member

I want a non-const private static data member with a default value like this:

1
2
3
4
5
6
7
8
9
10
11
12
class Matrix
{
private:
    
    static bool in_error;

    //...

};

bool Matrix::in_error = false;


but I get this error:

|error: 'bool Matrix::in_error' is private|

It works fine if I make it public, but I would prefer it be private for my implementation. Is there some other way to initialize a static member?
In your constructor?
1
2
public:
   Matrix () : in_error(false);
I just figured it out. I forgot to put the class scope operator on one of my member functions that use the static member. The error it produced was indicating the static member initialization rather than the function that was using it out of scope. So that was a little misleading. It works fine as I implemented it above.

Thanks!
Topic archived. No new replies allowed.