Scope of dimension parameters of outside-of-class defined matrix

Say I have the following code

class C {
    static const int dim = 3;
    static const int matrix[dim][dim];
};



int dim = -2;
const int C::matrix[dim][C::dim] = {{1,2,3}, {1,2,3}, {1,2,3}};

  1. Why am I obliged to state the dimensions of the matrix again?
  2. Why does the first dim = 3 and not -2?

My research has shown me interesting stuff (like initialization != definition) but I haven’t found this info in the C++ standard.

>Solution :

Why am I obliged to state the dimensions of the matrix again?

Because that is part of the type. matrix is an object of type const int [3][3]

Why does the first dim = 3 and not -2?

You are defining a member of C, so name lookup finds C::dim before it looks in ::.

Leave a Reply