Thread View: comp.std.c++
1 messages
1 total messages
Started by Desmond Dsouza
Thu, 18 Oct 1990 16:36
static data members which are arrays
Author: Desmond Dsouza
Date: Thu, 18 Oct 1990 16:36
Date: Thu, 18 Oct 1990 16:36
62 lines
1979 bytes
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
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads