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? 3 2112
<- 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 };
"<- Chameleon ->" <ch******@hotma il.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
"<- Chameleon ->" <ch******@hotma il.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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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:
|
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:
|
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
{
|
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 classes is only allowed for integral consts, like
static const enum and static const int, not for arrays and structs. It does
make sense for an array of integral consts though."
I read the above statements in this group a while back. First off,...
|
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:
http://www.parashift.com/c++-faq-lite/newbie.html#faq-29.6
"Here is another even more common example:
class Fred {
public:
...
private:
| |
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 fine.
1 / Now If I move the getSpectrumAtDistance( const T &dist ) method
definition in SpectralProfofile.cc let's say the compiler says
core/profile.cc:199: error: `kNumBins' was not declared in this scope
|
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 member inside my class.
class Packet
{
static const int session_id;
|
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)
|
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 MFC's
CPtrArray.
I've also exposed a public function from Entity - let's say it's
called foo. This function accesses the private static data (the string
array).
I have multiple instances of Entity stored in a custom C++ container,
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| | |