By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,908 Members | 2,055 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,908 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
}
---------------------------------
So, What to do?
Jul 22 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
<- Chameleon -> wrote:
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
}
---------------------------------
So, What to do?

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

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

Jul 22 '05 #2

P: n/a
"<- Chameleon ->" <ch******@hotmail.NOSPAM.com> wrote in message:
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

Jul 22 '05 #3

P: n/a
"<- Chameleon ->" <ch******@hotmail.NOSPAM.com> wrote in message:
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:

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
Jul 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.