🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #546

static data members which are arrays

#546
From: Desmond Dsouza
Date: Thu, 18 Oct 1990 16:36
62 lines
1979 bytes
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
Technical Details
Message-ID: <DSOUZA.90Oct18113608@optima.cad.mcc.com>
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!cs.utexas.edu!milano!cadillac!dsouza

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!cs.utexas.edu!milano!cadillac!dsouza
From: dsouza@optima.cad.mcc.com (Desmond Dsouza)
Newsgroups: comp.std.c++,comp.lang.c++
Subject: static data members which are arrays
Message-ID: <DSOUZA.90Oct18113608@optima.cad.mcc.com>
Date: 18 Oct 90 16:36:07 GMT
Sender: news@cadillac.CAD.MCC.COM
Organization: MCC CAD Program, Austin, Texas
Lines: 62