"Shezan Baig" <sh************@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Generic Usenet Account wrote: I am trying to compile the following sample code:
class WhatISHappeningHere
{
static const int x = 32;
static const char* yy = "Howdy";
// ...
// blah blah blah
// ...
};
My GCC compiler (g++ version 2.95.2) is giving the following
misleading compiler error:
ANSI C++ forbids in-class initialization of non-const static member
`yy'
I suspect that initialization of static data members that are not of
an integral type is not allowed in C++, but the compiler is giving a
wrong error message. Kindly confirm/refute my observation.
Thanks,
Gus
I'm not sure if this will work, but try:
static const char* const yy = "Howdy";
That won't work, either. As the OP thought, you're not allowed to
initialize static data members in the class definition, unless they're of
integral type. They need to be initialized outside the class definition
(and outside the header file, if you're using one, to avoid multiple
definitions).
Like you, I was thinking that the reason the compiler is saying that's
"non-const" is that it's a const ponter, but to non-const data. But making
it const data won't help here. It has to be an integral type to be
initialized "in class".
-Howard