[LC++]static const char*

Grzegorz Mazur mazur at chemia.uj.edu.pl
Fri Dec 14 05:08:04 UTC 2001


Hi,

On Thu, 13 Dec 2001 ianezz at sodalia.it wrote:

> Roberto Diaz, pigiando tasti a caso sul citofono, ha scritto:
> 
>  > class foo 
>  > {
>  >  static const int a = 1;
>  >  // more things
>  > };
> 
>  > I have no problems the compiler wont complaints..
> 
> That's strange, AFAIK it should complain in the same manner in both
> cases. This is Java-like syntax, C++ doesn't work this way.
> 
> It shouldn't be possible to define AND initialize static
> members in C++ (perhaps it doesn't complain because of basic
> optimizations perfomed on integer constants?), and the correct way
> should be:

It's not because of optimization - AFAIR the c++ standard allows for
in-class static const member initialization as far as they are of an
integral type. IMO this is why the example works with int and doesn't 
work with char*.

Cheers,
Grzesiek




More information about the tuxCPProgramming mailing list