Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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 ::.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading