Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!samsung!olivea!tardis!tymix!uunet!taumet!steve From: steve@taumet.com (Stephen Clamage) Newsgroups: comp.lang.c++ Subject: Re: use of const within a class to dimension arrays (can do?) Message-ID: <775@taumet.com> Date: 20 Jun 91 16:08:36 GMT References: <359@secola.Columbia.NCR.COM> Distribution: comp.lang.c++ Organization: Taumetric Corporation, San Diego Lines: 33 jmartin@secola.Columbia.NCR.COM (John Martinez) writes: >Is there any way to use a const within a class as the size of an array >which is also a member of the class? No, unless you use an enum constant (ugh). >class Minimal { > static const int ARRAY_SIZE; > static int array[ARRAY_SIZE]; // "error - constant expression required" >}; >const int Minimal::ARRAY_SIZE=10; >This generates an error, presumably because ARRAY_SIZE, while const, doesn't >count as _really_ constant until it is given a value. No, the array size must be a compile-time constant, and declaring a member static const int ARRAY_SIZE; or const int ARRAY_SIZE; does not create a compile-time constant, but does create storage for a class field. I agree that this is a language deficiency. At the moment, the best you can do is this: class Minimal { enum { ARRAY_SIZE = 10 }; static int array[ARRAY_SIZE]; }; -- Steve Clamage, TauMetric Corp, steve@taumet.com