From 5836651164753899931
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,942dd48e323646a4
X-Google-Attributes: gidf78e5,public
From: Ole Reinartz <ole.reinartz@gmx.de>
Subject: Re: const static member in a class
Date: 2000/05/26
Message-ID: <392E5925.6BABB160@gmx.de>#1/1
X-Deja-AN: 627579348
Content-Transfer-Encoding: 7bit
Approved: Fergus Henderson <fjh@cs.mu.oz.au>, moderator of comp.std.c++
References: <3908CCBC.E02307C@hotmail.com> <jRZNYBDqKCC5Ewpe@robinton.demon.co.uk>
X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f
Content-Type: text/plain; charset=us-ascii
X-Complaints-To: abuse@demon.net
X-Mail2News-Path: news.demon.net!mulga.cs.mu.oz.au
X-Trace: mail2news.demon.co.uk 959347458 mail2news:24908 mail2news mail2news.demon.co.uk
Organization: Nokia
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
MIME-Version: 1.0
NNTP-Posting-Date: Fri, 26 May 2000 13:29:10 EET DST
Newsgroups: comp.std.c++

Francis Glassborow wrote:

> In article <3908CCBC.E02307C@hotmail.com>, Yaxun Liu
> <yx_liu@hotmail.com> writes
> >Hi,
> >  I wonder whether the following codes satisfy the C++ standard,
> >
> >class A
> >{
> >public:
> >static const int m_a=1;
> >};
> >
> >I've seen some people used such codes, however, it caused compling error
> >
> >in VC++5.0. I was rather confused.
>
> This one is not really MS's fault as in class initialisation of static
> const data (integer types only) was a late tweak to the Standard.  In
> addition you still have to define the variable exactly once somewhere in
> your program (for the linker)
>

AFAIK in that special case you dont even have to define it for the linker
somewhere, because it is a constant. Because it will never change it doesnt
have to have a fixed location. The compiler is even allowed to optimize it
to a literal constant (like it would do when you would #define m_a 1). Still
the type savety remains.
Also I think (didnt look it up in the standard though) that it works for all
the builtin types.

Ole

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]




