class A { private: static const int a[] = {100,200}; };

J

Jeff Schwab

I know that MS VC++6 has problems in this syntax:
---------------------------------
class A {
private:
static const int a = 5;
}
---------------------------------
The hack is to use "enum" instead, but in my case below I don't know what to do:
---------------------------------
class A {
private:
static const int a[] = { 5, 6, 1, 4, ....................... }; // up to 400 values
}


class A {
static int const a[ ];
};

int const A::a[ ] = { 5, 6, 1, 4 };
 
J

Jonathan Turkanis

I know that MS VC++6 has problems in this syntax:
---------------------------------
class A {
private:
static const int a = 5;
}
---------------------------------
The hack is to use "enum" instead, but in my case below I don't know what to do:
---------------------------------
class A {
private:
static const int a[] = { 5, 6, 1, 4, ....................... }; // up to 400 values
}

This is not an MSVC-specific problem: C++ only allows in-class
initializers on static members of constant intergral or enumeration
type (C++2003 9.2/4).

Jonathan
 
J

Jonathan Turkanis

I know that MS VC++6 has problems in this syntax:
---------------------------------
class A {
private:
static const int a = 5;
}
what to do:

Another point: using an enum is not necessarily a hack. A static
constant member is an lvalue whose address can be taken and which
therefore incurs some (small) runtime cost. Sometimes it is desirable
to avoid this cost, esp. in template metaprogramming.

Jonathan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,754
Messages
2,569,527
Members
44,998
Latest member
MarissaEub

Latest Threads

Top