472,098 Members | 2,565 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,098 software developers and data experts.

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

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
3 2022
<- 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
"<- 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
"<- 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.

Similar topics

14 posts views Thread by | last post: by
1 post views Thread by Steven T. Hatton | last post: by
4 posts views Thread by cppsks | last post: by
12 posts views Thread by Philip Potter | last post: by
5 posts views Thread by mast2as | last post: by
7 posts views Thread by Spoon | last post: by
18 posts views Thread by mati | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.