Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!snorkelwacker.mit.edu!stanford.edu!lma@dayton.Stanford.EDU From: lma@dayton.Stanford.EDU (Larry Augustin) Newsgroups: comp.lang.c++ Subject: const vs. static in class declaration Summary: what is the correct way to do this? Keywords: const, static, class constants Message-ID: <286@dayton.stanford.edu> Date: 26 Mar 91 22:55:45 GMT Lines: 49 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. Just so you understand the context, there may also be a class: class bar { private: ... protected: ... public: const int ID = 230; const int NUMBER = 231; const int IPORT = 232; ... }; So I don't simply want to use a #define or a global constant. Thanks, Larry M. Augustin ERL 414 lma@sierra.stanford.edu Computer Systems Lab lma@dayton.stanford.edu Stanford University (415) 723-9285 Stanford, CA 94305 -- Larry M. Augustin _ _ _ ____ | | | \ / | / __ \ ARPA: lma@sierra.stanford.edu | | | \__/ | | (__) | BITNET: lma%sierra.stanford.edu@stanford | | | |\ /| | | __ | UUCP:...!ucbvax!sierra.stanford.edu!lma | |____ | | \/ | | | | | | AT&T: (415) 324-4929 |______| |_| |_| |_| |_|