Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!elroy.jpl.nasa.gov!decwrl!fernwood!dumbcat!marc From: marc@dumbcat.sf.ca.us (Marco S Hyman) Newsgroups: comp.lang.c++ Subject: Re: macros (was: const vs. static in class declaration) Keywords: macros, inline Message-ID: <287@dumbcat.sf.ca.us> Date: 10 Apr 91 05:00:04 GMT References: <1991Apr5.211511.19618@csi.uottawa.ca> <660@taumet.com> <1991Apr9.175539.29221@prl.dec.com> Distribution: na Organization: MH Software, Hayward, CA. Lines: 36 In article <1991Apr9.175539.29221@prl.dec.com> weikart@prl.dec.com (Chris Weikart) writes: > char *blah_blah[] = > { > "When you can use a constant, use it. When you can't, like here,", > "then do what DIM does, with or without DIM. Since it only works", > "on genuine arrays (i.e. declared as such, buffers, not pointers),", > "this seems to be a good general strategy." > } > > unsigned int blah_blah_num = DIM(blah_blah); But a macro was not needed for the original question. An enum can be used -- if you don't mind using an enum where it doesn't (conceptually) belong. The following compiles without warning using a cfront 2.0 based compiler. class jive { public: void tweak() {} }; class array_of_jive { public: enum jive_constants { num_elements = 10 }; jive a[num_elements]; void tweak_all() { for ( int i = 0 ; i < num_elements; ++i ) a[i].tweak(); } }; -- // marc // home: marc@dumbcat.sf.ca.us pacbell!dumbcat!marc // work: marc@ascend.com uunet!aria!marc