Newsgroups: comp.lang.c++ Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!ispd-newsserver!tuna!randolph From: randolph@tuna.ssd.kodak.com (Gary L. Randolph) Subject: Re: Static member definition vs. declaration? Message-ID: <1991May8.120340.176@ssd.kodak.com> Sender: news@ssd.kodak.com Organization: Eastman Kodak References: <1991Apr19.133728.5300@clear.com> <1991Apr30.195846.16760@ccad.uiowa.edu> <72218@microsoft.UUCP> Date: Wed, 8 May 91 12:03:40 GMT In article <72218@microsoft.UUCP> jimad@microsoft.UUCP (Jim ADCOCK) writes: >|We have a debate in our group. When you declare a static >|member, such as: >| >| class X {static int myVar;}; >| >|Do you need to make a definition elsewhere, >| >| int X::myVar; >| > >In C++ static members are only allowed for global classes. The mention of such >inside of the class is only a declaration, the actual definition must >occur at file scope. > >Some C++ compilers allow declaration without such explicit definition. >This is a *compiler* anachronism as listed in section 18.3 of ARM, not part >of the C++ *language* as defined today. What Jim says is certainly true. I have an additional comment and a suggestion that you obviously may ignore. comment: One point that may be news to at least the novice C++er is that static members have external linkage. This is not what C programmers are used to. In fact many programmers believe that static MEANS private and permanent. Usually it does. This is an exception. suggestion: As Jim implies, you should never rely on a compiler allowing you to forego the definition. Gary