This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: c++/3800: A value of const static class attribute cannot be used in STL

On Jul 27, 2001, Milan Krčmář <> wrote:

> If I define any constant static member array|struct with value inside
> class body, the compiler emits an error. The error is not emited for
> constant static int and unsigned (and probably all the simple types as
> char, ...). If, according to the standard, it is not allowed to define (=
> together with its value)  simple const static members inside class body,
> the compiler should emit an error, too.

You are allowed to declare with an initializer a static data member of
constant integral type inside the class body, but this doesn't mean
you don't have to define the static data member outside the class
body.  In C++, for every:

class foo {
  static ..... bar;

there must be a:

.... foo::bar;

outside the class body, regardless of the type or constness of
foo::bar.  If foo::bar is of constant integral type, and the
initializer is given inside the class body, foo::bar may be used in
constant expressions, and the definition must not contain an
initializer, but the definition must still be present.  If you don't
believe this, see []/4.

Alexandre Oliva   Enjoy Guarana', see
Red Hat GCC Developer                  aoliva@{,}
CS PhD student at IC-Unicamp        oliva@{,}
Free Software Evangelist    *Please* write to mailing lists, not to me

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]