Path: utzoo!mnetor!tmsoft!torsqnt!jarvis.csri.toronto.edu!rutgers!dptg!pegasus!psrc From: psrc@pegasus.ATT.COM (Paul S. R. Chisholm) Newsgroups: comp.lang.c++ Subject: Re: Class initialization Summary: kludgey way to have a private class constant Message-ID: <4100@pegasus.ATT.COM> Date: 20 Sep 89 03:41:19 GMT References: Distribution: comp Organization: AT&T Bell Laboratories Lines: 29 In article , dougm@rhea.rice.edu (Doug Moore) writes: > How do you declare and initialize a private constant value local > to a class? In an implementation of Stack, for example, I want the > constant MAX_STACK_SIZE to have some hidden value. In C, I would > #define it. In C++, I can do no better than make a static const > private member, but then it takes up space. I could have many such > constants, not properly groupable into an enum type, and I would have > to have runtime storage for all of them. Is there a better way? And the static private member function can't be initialized in the header file (at least not in 1.2.3), and can't be used to set an array bound. This question came up in a C++ mailing list that a friend of mine is on (and I have *no* information about, so please don't ask). Four people came up with the same answer. You're going to hate it: private: enum { MAX_STACK_SIZE = 1024 }; That is, an unnamed enum type with one initialized value. Sometimes I miss Pascal, y'know? > Doug Moore (dougm@rice.edu) Paul S. R. Chisholm, AT&T Bell Laboratories att!pegasus!psrc, psrc@pegasus.att.com, AT&T Mail !psrchisholm I'm not speaking for the company, I'm just speaking my mind.