Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!apple!vsi1!octopus!sjsumcs!horstman From: horstman@sjsumcs.sjsu.edu (Cay Horstmann) Newsgroups: comp.lang.c++ Subject: constants inside structures Message-ID: <1990Mar13.082527.10207@sjsumcs.sjsu.edu> Date: 13 Mar 90 08:25:27 GMT References: <11024@saturn.ucsc.edu> <5104@odin.SGI.COM> Reply-To: horstman@sjsumcs.SJSU.EDU (Cay Horstmann) Organization: San Jose State University Lines: 27 Suppose I wish to hide a numeric constant inside a struct, to avoid cluttering the global name space, and suppose that constant gives the size of another array in the struct. Kind of like struct X { static const int SIZE; int a[ SIZE ]; }; const int X::SIZE = 10; except of course that doesn't work. But struct X { static const int SIZE = 10; int a[ SIZE ]; }; is illegal. I know I could declare X_SIZE outside X, but I LIKE the idea behind static data and functions inside structs/classes. Why clutter up the global name space if you don't have to? Why indeed is the second form declared illegal? It sure beats the yucky syntax of the first case. (Same for initializers of static variables...) Cay