Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!ucsd!ogccse!blake!uw-beaver!rice!brazos.rice.edu!dougm From: dougm@rhea.rice.edu (Doug Moore) Newsgroups: comp.lang.c++ Subject: Class initialization Message-ID: Date: 17 Sep 89 08:10:20 GMT Sender: root@rice.edu Distribution: comp Organization: /titan2/dougm/.organization Lines: 22 Here are two situations that I, as a newcomer to C++, can't figure out how to handle in the C++ way, only in a kludgey way: 1. 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? 2. How do you initialize some data structures for a class? For creating a new object of the class, I know how. Consider, for example, a Stack class, where a static array of fixed size is to hold all the items in all the Stacks. A free space stack must be initialized before the first item is pushed onto a stack. The only way I know to set up the necessary data structure is to have a flag initialized to TRUE that triggers the free-list initialization on the creation of the first Stack, after which the flag is reset. Also pretty ugly. Is there a C++-ish way to do this? Doug Moore (dougm@rice.edu)