Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!sdd.hp.com!hplabs!hpfcso!hpfcbig!jenings From: jenings@hpfcbig.SDE.HP.COM (Byron Jenings) Newsgroups: comp.lang.c++ Subject: Re: const vs. static in class declaration Message-ID: <7180016@hpfcbig.SDE.HP.COM> Date: 29 Mar 91 02:59:20 GMT References: <286@dayton.stanford.edu> Organization: HP SESD, Fort Collins, CO Lines: 44 Larry Augustin writes: |I have a number of integer constants that are part of a class. What |is the correct way to go about doing this? I have been using: | class foo { | private: | ... | protected: | ... | public: | const int ID = 258; | const int NUMBER = 259; | const int IPORT = 260; | ... | }; |But I've been told that this only works in g++, and isn't standard. I |would like to avoid doing anything in my my application that isn't |portable. I believe that this is the proper way to do this: In the header file: class foo { private: ... protected: ... public: static const int ID; // note that 'static' doesn't refer to linking static const int NUMBER; static const int IPORT; ... }; Then, in the corresponding C++ source file that implements the members of class foo: const int foo::ID = 258; const int foo::NUMBER = 259; const int foo::IPORT = 260;