Path: utzoo!attcan!uunet!ncrlnk!ncrcae!hubcap!gatech!uflorida!ukma!tut.cis.ohio-state.edu!osu-cis!att!ihlpb!nevin1 From: nevin1@ihlpb.ATT.COM (Liber) Newsgroups: comp.lang.c++ Subject: Re: consts in classes Keywords: const class static ANSI Message-ID: <9055@ihlpb.ATT.COM> Date: 11 Nov 88 01:29:55 GMT References: <155@peritus.UUCP> Reply-To: nevin1@ihlpb.UUCP (55528-Liber,N.J.) Organization: AT&T Bell Laboratories - Naperville, Illinois Lines: 38 In article <155@peritus.UUCP> preston@peritus.UUCP (Preston Gardner) writes: |Is it possible to define a const inside of a class? I think so. |Suppose I want to do this: | class XType { | const int MAX = 20; // I don't like the C preprocessor define | int array[MAX]; | | void XYZ() { // uses array and MAX somehow | }; | }; Declaring MAX as a const static int should work. |Another question: Is there one per object, or one for the whole type? Since it is declared as static, there is only one for the whole type. Just wondering: are there any situations where it would be useful to have a separate constant per object, instead of just having one for the whole class (and would initialization then be dependent on #ifdef/#endif in the library files -- very ugly IMHO)? |If there is one for the whole type then they would be a lot like static |class fields. That is exactly what they are. Hope this helps (and is correct; I'm a bit sleepy right now and my reference material is in the trunk of my car), -- _ __ NEVIN J. LIBER ..!att!ihlpb!nevin1 (312) 979-4751 IH 4F-410 ' ) ) "I catch him with a left hook. He eels over. It was a fluke, but there / / _ , __o ____ he was, lying on the deck, flat as a mackerel - kelpless!" / (_