[comp.std.c++] static data members which are arrays

dsouza@optima.cad.mcc.com (Desmond Dsouza) (10/18/90)

What are the rules for initialization of static class data members
which are arrays? Specifically:

1. Is an explicit size required in the declaration in the class?
2. Do arrays of built-in types follow the same rules as arrays of
   class types?
3. If an explicit size is required: WHY is it optional for global
   variables and required for static class members? 

The ARM (p.289-290) is not explicit on this point, and the examples
included all have explicit sizes in them.

Sun C++ and Gnu G++ both behave as indicated in the example below:


------------------------------------------------------------

enum PLACEHOLDER {X1, X2};

class Act {
public:
  Act(PLACEHOLDER p) : mem(p) {} 

  // data members
  PLACEHOLDER mem;
};





class FOO {
public:
  static int i1[];
  static int i2[2];
  static Act a1[];
  static Act a2[2];
};


int FOO::i1[] = {1,2};		// works fine for int[]

int FOO::i2[2] = {1,2};		// fine for int[]

Act globalArr[] = { Act(X1), Act(X2) };	// fine for globals with constructor


Act FOO::a1[] = { Act(X1), Act(X2) }; // **** error for static member with constructor


Act FOO::a2[2] = { Act(X1), Act(X2) }; // fine for *sized* static member with constructor




----------------------------------------------------------------------
--

-------------------------------------------------------------------------------
 Desmond D'Souza, MCC CAD Program | ARPA: dsouza@mcc.com | Phone: [512] 338-3324
 Box 200195, Austin, TX 78720 | UUCP: {uunet,harvard,gatech,pyramid}!cs.utexas.edu!milano!cadillac!dsouza