[LC++]static const char*
ianezz at sodalia.it
ianezz at sodalia.it
Fri Dec 14 04:54:06 UTC 2001
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:
----------------------------------------------------------------------
Foo.h
----------------------------------------------------------------------
class Foo
{
private:
static const int a;
static const char * a_char_ptr;
// more things...
}
----------------------------------------------------------------------
Foo.cpp
----------------------------------------------------------------------
#include "Foo.h"
const int
Foo::a = 1;
const char *
Foo::a_char_ptr = "text";
--
UNIX diapers by Pannolini USPTO 2039887 http://www.uspto.gov
Matteo Ianeselli ianezz AT sodalia.it (+39) 0461 316452
Visita il LinuxTrent: http://www.linuxtrent.it
More information about the tuxCPProgramming
mailing list