Phlip wrote in news:ey*******************@newssvr32.news.prodigy. com:
This is all well-formed, with defined behavior:
class yo { public:
static int z (42);
};
char whatever[yo::z];
But an enum would have worked the same, too.
Also if you also want to use the static integral constant in a
non-compile-time context you also need a definition outside the class,
/* Not in a header file (templates aside)
*/
int yo::z; /* Note no initializer */
int main()
{
int z = yo::z;
int const *zp = &yo::x;
}
enum's don't have this requirment, which is perhapse one way in which
enum's are "better" than static int const's.
Cranking the level of triviality up a notch. An instance of an enum
can also be a static integral constant,
#include <iostream>
struct A
{
enum B { C, D, E };
static B const b = A::E;
};
A::B const A::b;
int main()
{
std::cerr << A::b << "\n";
}
Rob.
--
http://www.victim-prime.dsl.pipex.com/