473,396 Members | 1,917 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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 2087
<- 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: | last post by:
I read in "Thinking in C++" this code works: --------- class A { static const int b = 1; }; --------- but it doesn't! I do something wrong? I use VC++6 and it returns:
7
by: qazmlp | last post by:
What do you recommend among the following two designs, considering all the standard design aspects ? 1) class base { public: virtual ~base() { } virtual long int getId() = 0; private:
1
by: Steven T. Hatton | last post by:
Is there a way to initialize an member array of user defined objects that is declared static const? For example: const vec3f I(1,0,0); const vec3f j(0,1,0); class corner_functor {
4
by: cppsks | last post by:
"Defining static const variables inside the class is not universally supported yet, so for now I guess you'll have to move the definition out of the body of the class. No, static const inside...
12
by: Philip Potter | last post by:
I'm reading the comp.lang.c++ faq and, though it is incredibly clear and lucid in many points, I am completely confused by question 29.6: ...
5
by: mast2as | last post by:
Hi guys Here's the class I try to compile (see below). By itself when I have a test.cc file for example that creates an object which is an instance of the class SpectralProfile, it compiles...
7
by: Spoon | last post by:
Hello everyone, I have a Packet class I use to send packets over the Internet. All the packets sent in a session are supposed to share a common random ID. I figured I'd use a static const...
18
by: mati | last post by:
Hi The following code works: #include <vector> class C { private: static const int m_static = 2; public: void f(const std::vector<int>& v)
5
by: Stodge | last post by:
I've exposed a C++ class to Python using Boost Python. The class, let's say it's called Entity, contains private static data, which is an array of strings. Though I think it implements it using...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.