Path: utzoo!utgpu!attcan!uunet!husc6!bloom-beacon!apple!voder!pyramid!oliveb!peritus!preston From: preston@peritus.UUCP (Preston Gardner) Newsgroups: comp.lang.c++ Subject: consts in classes Keywords: const class static ANSI Message-ID: <155@peritus.UUCP> Date: 10 Nov 88 01:56:47 GMT Organization: Peritus International, 10201 Torre, Cupertino, CA. Lines: 29 Is it possible to define a const inside of a class? I tried to do it in various ways, but I could never work out a way to initialize it. (Const objects without initialization are useless in C++ and cfront squawks if it sees them. Cf. ANSI consts, which can be uninitialized, e.g. a const volatile object that refers to a read-only I/O register. The ANSI idea of const is different.) 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 }; }; I can't really get it in C++. I don't know how to get the definition of MAX confined within the scope of XType, except to use #define and #undef. Another question: Suppose that it is possible to have const objects inside of a class. Is there one per object, or one for the whole type? If there is one for the whole type then they would be a lot like static class fields. -- -- Preston Gardner Peritus International, Inc. ..{pyramid,sun}!oliveb!peritus!preston