473,325 Members | 2,308 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,325 software developers and data experts.

class A{static const int b = 1; };

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:
-------
error C2258: illegal pure syntax, must be '= 0'
error C2252: 'b' : pure specifier can only be specified for functions
-------
Jul 19 '05 #1
14 4451
WW
<- Chameleon -> wrote:
I read in "Thinking in C++" this code works:
---------
class A
{
static const int b = 1;
};
---------
but it doesn't!
I do something wrong?


No. VC6 is non-standard in this matter. The usual fix is the enum-as-const
"idiom". Just do it like this:

class A
{
enum { b = 1; };
};

--
WW aka Attila
Jul 19 '05 #2
"WW" <wo***@freemail.hu> wrote...
<- Chameleon -> wrote:
I read in "Thinking in C++" this code works:
---------
class A
{
static const int b = 1;
};
---------
but it doesn't!
I do something wrong?
No. VC6 is non-standard in this matter. The usual fix is the

enum-as-const "idiom". Just do it like this:

class A
{
enum { b = 1; };
enum { b = 1 };
};


Victor
Jul 19 '05 #3

Victor Bazarov wrote:
[...]
enum { b = 1; };


enum { b = 1 };


"The actual eyeballs, lying within an ea^H^H^H^H^HBazarov's skull, are
huge by our standards, taking up more room than the brain itself!"

http://amos.indiana.edu/library/scripts/eagle.html

regards,
alexander.
Jul 19 '05 #4
WW
Victor Bazarov wrote:
class A
{
enum { b = 1; };


enum { b = 1 };
};


Thanks for the correction. I forgot to remove the ;. It is so little I did
not see it is there. That is again a proof that size does not matter ;-)

--
WW aka Attila
Jul 19 '05 #5
WW
Alexander Terekhov wrote:
Victor Bazarov wrote:
[...]
enum { b = 1; };


enum { b = 1 };


"The actual eyeballs, lying within an ea^H^H^H^H^HBazarov's skull, are
huge by our standards, taking up more room than the brain itself!"


I assume Alexander meant you have eagle eyes. And nothing about Victor's
brain.

Alexander, you will really need a bodyguard. My father has jokes like this
and the people of his village did confess to me that they have sometimes
played with the idea to check if his brain differs from a normal one. ;-)

--
WW aka Attila
Jul 19 '05 #6
"WW" <wo***@freemail.hu> wrote...
[...]
I assume Alexander meant [...]


He didn't mean anything. He can't mean anything.
He has no device with which to mean.
Jul 19 '05 #7
WW
Victor Bazarov wrote:
"WW" <wo***@freemail.hu> wrote...
[...]
I assume Alexander meant [...]


He didn't mean anything. He can't mean anything.
He has no device with which to mean.


I see. He has no device with which to mean. So he cannot be mean. ;-)
Jul 19 '05 #8

WW wrote:
[...]
I assume Alexander meant you have eagle eyes. And nothing about Victor's
brain.


Let me put it this way. Judging from Bazarov's "subdue" c.l.c++-policing
activity of lately, his medical treatment looks really promising. To me,
it seems like he'll reach the level of NeilB really soon. Amen. Default,
be ready (never mind your days are coming too).

http://groups.google.com/groups?selm...A3F4C%40web.de

regards,
alexander.
Jul 19 '05 #9
Alexander Terekhov wrote:
WW wrote:
[...]
I assume Alexander meant you have eagle eyes. And nothing about Victor's
brain.

Let me put it this way. Judging from Bazarov's "subdue" c.l.c++-policing
activity of lately, his medical treatment looks really promising. To me,
it seems like he'll reach the level of NeilB really soon. Amen. Default,
be ready (never mind your days are coming too).

http://groups.google.com/groups?selm...A3F4C%40web.de


So what did end up happening to the butter man. Is he Alexander now ?

Jul 19 '05 #10
"<- Chameleon ->" <ch******@hotmail.NOSPAM.com> wrote in message news:<bk*********@nic.grnet.gr>...
I read in "Thinking in C++" this code works:
---------
class A
{
static const int b = 1;
};
---------
but it doesn't!
<http://www.comeaucomputing.com/tryitout/> compiles it just fine. If
you're going to use a compiler as a measure of code correctness, use
that one. :)
I do something wrong?
I use VC++6 and it returns:
-------
error C2258: illegal pure syntax, must be '= 0'
error C2252: 'b' : pure specifier can only be specified for functions
-------


VC++6 is wrong. VC++.NET compiles it.

In the short term, maybe try this instead:

class A { enum { b = 1 }; };

Or, if you don't need it as a compile-time constant (e.g., for use as
a template parameter, size of an array, etc.), initialize it when you
define it in a .cpp file:

// A.h
class A {
static const int b;
};

// A.cpp
const int A::b = 1;

- Shane
Jul 19 '05 #11
"WW" <wo***@freemail.hu> wrote...
Victor Bazarov wrote:
"WW" <wo***@freemail.hu> wrote...
[...]
I assume Alexander meant [...]


He didn't mean anything. He can't mean anything.
He has no device with which to mean.


I see. He has no device with which to mean. So he cannot be mean. ;-)


Nah. It's actually simpler. He cannot be. Unless you let him,
by replying to his nonsense. Two more times and you (and others
feeding that idiot troll) will probably join him in my killfile.
You don't have to care about that. I'm just pondering.
Jul 19 '05 #12
WW
Victor Bazarov wrote:

Nah. It's actually simpler. He cannot be. Unless you let him,
by replying to his nonsense. Two more times and you (and others
feeding that idiot troll) will probably join him in my killfile.
You don't have to care about that. I'm just pondering.


If you killfile me I cannot send you my C++ language proposal for review.
It would be shame. How do you expect *me* to get it right? Drop me a mail
if you think you would have time and want to look at something like that.

BTW I was not trying to feed any troll, I was trying to keep the tension
down. Well, remind me time to time to not seek for a carrier in marriage
concunciling. :-(

--
WW aka Attila
Jul 19 '05 #13
WW
WW wrote:
[SNIP]
tension down. Well, remind me time to time to not seek for a carrier
in marriage concunciling. :-(


And to not to teach spelling..

--
WW aka Attila
Jul 19 '05 #14

Victor Bazarov wrote:

"WW" <wo***@freemail.hu> wrote...
Victor Bazarov wrote:
"WW" <wo***@freemail.hu> wrote...
> [...]
> I assume Alexander meant [...]

He didn't mean anything. He can't mean anything.
He has no device with which to mean.
I see. He has no device with which to mean. So he cannot be mean. ;-)


Nah. It's actually simpler. He cannot be. Unless you let him,
by replying to his nonsense. Two more times and you (and others
feeding that idiot troll) will probably join him in my killfile.


Aha. How scary.
You don't have to care about that. I'm just pondering.


Medication, Bazarov. Take a dose of anti-hysteria pills.

regards,
alexander.
Jul 19 '05 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: DanielBradley | last post by:
Hello all, I have recently been porting code from Linux to cygwin and came across a problem with static const class members (discussed below). I am seeking to determine whether I am programming...
3
by: Steven T. Hatton | last post by:
Sorry about the big code dump. I tried to get it down to the minimum required to demonstrate the problem. Although this is all done with GNU, I believe the problem I'm having may be more general. ...
2
by: Jonas Cord | last post by:
Hi, I'm trying to learn proxy classes in C++ so I've written the following code, trying to modify an example given in Deitel & Deitel's C++ book. I am trying to "hide" details of the original...
10
by: Not Available | last post by:
On the host server: namespace JCart.Common public class JCartConfiguration : IConfigurationSectionHandler private static String dbConnectionString; public static String ConnectionString { get...
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...
14
by: Gary Wessle | last post by:
Hi how can I initialize a const char* myarr in a class constructor? class Myclass { const char* myarr = { "abc", "def" }; .... };
8
by: Bern McCarty | last post by:
I have a simple ref class in its own namespace that needs to coexist with a legacy typedef alias for "unsigned int" in the global namespace that has the identifier as itself. Everything compiles...
25
by: David Sanders | last post by:
Hi, As part of a simulation program, I have several different model classes, ModelAA, ModelBB, etc., which are all derived from the class BasicModel by inheritance. model to use, for example...
8
by: Per Bull Holmen | last post by:
Hey Im new to c++, so bear with me. I'm used to other OO languages, where it is possible to have class-level initialization functions, that initialize the CLASS rather than an instance of it....
5
by: alan | last post by:
Hello world, I'm wondering if it's possible to implement some sort of class/object that can perform mapping from class types to strings? I will know the class type at compile time, like so:...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.