Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!samsung!uunet!island!chris From: chris@island.COM (Chris King) Newsgroups: comp.lang.c++ Subject: Re: const vs. static in class declaration Keywords: const, static, class constants Message-ID: <3864@island.COM> Date: 2 Apr 91 17:32:14 GMT References: <286@dayton.stanford.edu> <139@grenada.island.COM> Organization: Island Graphics, Marin County, California Lines: 44 roger@grenada.island.COM (Roger Corman) writes: > Roger expains how to declare a const static class member. Initialization of const static class members are one thing that I really think have been poorly thought out in c++. I didn't realize that g++ allowed them to be initialized in the class decleration. This seems like a defininate improvment over cfront. I hope the ansi commitee will consider adding this g++ feature to the standard. In addition, one thing that I wish I could do is the following: class array_of_jive { static const int num_elements = 10; struct jive a[num_elements]; void tweak_all() { for ( int i = 0 ; i < num_elements; ++i ) a[i].tweak(); } }; but unfortunatly the compiler won't let me do this, so, rather than use a define (I hate defines), I usually do the following: class array_of_jive { struct jive a[10]; inline int num_elements() { return(sizeof(a)/sizeof(struct jive)); } void tweak_all() { for ( int i = 0 ; i < num_elements(); ++i ) a[i].tweak(); } }; Has anybody found a easier way of doing this. Chris King Island Graphics Corp. San Rafael Ca. {sun,ucbcad,uunet}!island!chris